对数组进行快速升降序排列,话不多说直接上代码
1.升序
NSArray *tMlist = @[@4,@5,@2,@6,@3,@7,@8];
NSArray *tArray = [tMlist sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSNumber *tNumber1 = (NSNumber *)obj1;
NSNumber *tNumber2 = (NSNumber *)obj2; //升序2,4,。。
if ([tNumber1 integerValue] < [tNumber2 integerValue]){
return NSOrderedAscending;
}else{
return NSOrderedDescending;
}
}];
2.降序
NSArray *tMlist = @[@4,@5,@2,@6,@3,@7,@8];
NSArray *tArray = [tMlist sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSNumber *tNumber1 = (NSNumber *)obj1;
NSNumber *tNumber2 = (NSNumber *)obj2; //降序序8,7,。。
if ([tNumber1 integerValue] < [tNumber2 integerValue]){
return NSOrderedDescending;
}else{
return NSOrderedAscending;
}
}];