标签:
NSArray *originalArray = @[@1,@2666661,@12,@11,@0]; //block比较方法,数组中可以是NSInteger,NSString(需要转换) NSComparator finderSort = ^(id string1,id string2){ if ([string1 integerValue] > [string2 integerValue]) { return (NSComparisonResult)NSOrderedDescending; }else if ([string1 integerValue] < [string2 integerValue]){ return (NSComparisonResult)NSOrderedAscending; } else return (NSComparisonResult)NSOrderedSame; }; //数组排序: NSArray *resultArray = [originalArray sortedArrayUsingComparator:finderSort]; NSInteger i = resultArray.count - 1; NSLog(@"排序结果:%@",resultArray); NSLog(@"排序结果最大:%@",resultArray[i]); NSLog(@"排序结果最小:%@",resultArray[0]);
标签:
原文地址:http://www.cnblogs.com/xsphehe/p/5866016.html