【代码笔记】iOS-对数组进行排序

来源:互联网 发布:客机纸模型图纸淘宝 编辑:程序博客网 时间:2024/06/05 07:10

一,代码。

复制代码
- (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)
复制代码
原创粉丝点击