#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//@"6",@"34",@"56","78"存入数组,并进行排序降序输出结果
NSArray*arr=@[@"6",@"34",@"56",@"78"];
NSComparator str=^(id obj1,id obj2){
int obj=[obj1 intValue];
int objc=[obj2 intValue];
if (obj<objc) {
return NSOrderedDescending;
}else if (obj==objc){
return NSOrderedSame;
}else{
return NSOrderedAscending;
}
};
NSArray *arr1=[arr sortedArrayUsingComparator:str];
for ( id str3 in arr1) {
NSLog(@"%@",str3);
}
NSComparator str2=^(id obj1,id obj2){
int obj=[obj1 intValue];
int objc=[obj2 intValue];
if (obj>objc) {
return NSOrderedDescending;
}else if (obj==objc){
return NSOrderedSame;
}else{
return NSOrderedAscending;
}
};
NSArray *arr2=[arr sortedArrayUsingComparator:str2];
for ( id str4 in arr2) {
NSLog(@"%@",str4);
}
}
return 0;
}