NSArray *_firstArray = [NSArrayarrayWithObjects:@"ccccc",@"bbbbb",@"ddddd",@"aaaaa",nil];
NSArray *_sortedArray= [_firstArray sortedArrayUsingSelector:@selector(compare:)];
NSLog(@"未排序:%@",_firstArray);
NSLog(@"排行后:%@",_sortedArray);
Objective-C NSArray排序示例
本文展示了一个使用Objective-C进行NSArray排序的例子,通过调用sortedArrayUsingSelector方法并传入compare选择器实现了对字符串数组的排序。代码示例中包含了未排序和排序后的数组输出。
NSArray *_firstArray = [NSArrayarrayWithObjects:@"ccccc",@"bbbbb",@"ddddd",@"aaaaa",nil];
NSArray *_sortedArray= [_firstArray sortedArrayUsingSelector:@selector(compare:)];
NSLog(@"未排序:%@",_firstArray);
NSLog(@"排行后:%@",_sortedArray);
转载于:https://www.cnblogs.com/qingjoin/archive/2013/05/07/3064782.html

被折叠的 条评论
为什么被折叠?