排序
- 数值排序
NSArray *tempArr=[NSArray arrayWithObjects:@"1",@"12",@"4",@"05",nil];
NSArray *sortArr_=[tempArr sortedArrayWithOptions:NSSortConcurrent usingComparator:^NSComparisonResult(id _Nonnull obj1, id Nonnull obj2) {
if ([obj1 floatValue]>[obj2 floatValue]) {
return NSOrderedDescending;
}else if ([obj1 floatValue]<[obj2 floatValue]){
return NSOrderedAscending;
}else{
return NSOrderedSame;
}
}];
NSLog(@"数值排序=%@",sortArr);
2016-05-10 16:07:56.912 Test[5238:463243] 数值排序=(
1,
4,
05,
12
)
- 字符串排序
NSLog(@"字符串排序=%@",[tempArr sortedArrayUsingSelector:@selector(compare:)]);
2016-05-10 16:07:56.912 Test[5238:463243] 字符串排序=(
05,
1,
12,
4
)