一般分为三种:
第一种 使用sortedArrayUsingSelector排序
SEL sel = @selector(compare:);
arr = [arr sortedArrayUsingSelector:sel];
第二种 使用 sortedArrayUsingDescriptors排序
NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"FriendName" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sorter count:1];
[self.myArray sortedArrayUsingDescriptors:sortDescriptors]
第二种 使用 sortedArrayUsingComparator排序
NSArray *sortedArray = [array sortedArrayUsingComparator: ^(id obj1, id obj2) {
if ([obj1 integerValue] > [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedDescending;
}
if ([obj1 integerValue] < [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];