NSArray *array = @[@1, @20, @3, @10, @2];
//排序后到新数组里
NSArray *sortedArray = [array sortedArrayUsingComparator:^NSComparisonResult(NSNumber* obj1, NSNumber* obj2) {
if ([obj1 intValue] > [obj2 intValue]) {
return NSOrderedDescending;
} else {
return NSOrderedAscending;
}
}];
NSLog(@"%@",sortedArray);
网友评论