NSArray *stringArray = [NSArray arrayWithObjects:@"zhangsan",@"lisi",@"wangjun",@"lanlan",@"yangyi",@"qianzhongshu",@"sunwukong",@"wugang", nil];
NSArray *sortedArray = [stringArray sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [obj1 compare:obj2];//顺序
return -[obj1 compare:obj2];//倒序(排序结果为枚举值[-1,0,1].所以想要得到排序结果在控制台倒序输出,加一个"-"即可。
}];
NSLog(@"%@",sortedArray);
Objective-C之Block与数组排序,布布扣,bubuko.com
原文:http://www.cnblogs.com/justdo-IT-/p/3818580.html