打印数组
#import "NSArray+Log.h"
@implementation NSArray (Log)
- (NSString *)descriptionWithLocale:(id)locale
{
NSMutableString *strM = [NSMutableString stringWithString:@"(\n"];
for (id obj in self) {
[strM appendFormat:@"\t%@,\n", obj];
}
[strM appendString:@")\n"];
return strM;
}
@end
数组排序
array = [array sortedArrayUsingComparator:^NSComparisonResult(NSNumber* obj1, NSNumber* obj2){
return [obj1 compare:obj2];
}];
数组乱序
array = [array sortedArrayUsingComparator:^NSComparisonResult(NSNumber* obj1, NSNumber* obj2){
int seed = arc4random_uniform(2); //-> 0、1
if(seed) {
return [obj1 compare:obj2];
} else {
return [obj2 compare:obj1];
}
}];