一,代码。
class="cnblogs_code_copy" style="font-size: 18px">- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//直接排序对象
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];
NSArray *descriptors = [NSArray arrayWithObject:descriptor];
NSArray *myDataArray = [NSArray arrayWithObjects:@"what", @"xero", @"highligth", @"mountain", @"Victory", @"Balance", nil];
NSLog(@"---myDataArray---%@",myDataArray);
NSArray *resultArray = [myDataArray sortedArrayUsingDescriptors:descriptors];
NSLog(@"%@", resultArray);
//NSArray 使用sortedArrayUsingDescriptors,返回排序好的数组。
//NSMutableArray可以直接使用sortUsingDescriptors,对数组本身排序。
}
二,输出。
2015-10-23 11:56:45.178 对数组进行排序[6739:168615] (
Balance,
Victory,
highligth,
mountain,
what,
xero
)