NSSortDescriptor
用于集合(数组、字典)排序的类
最常用的地方是NSFetchedResultsController中,但用法大致相同
可以根据多个属性排序
创建NSSortDescriptor
-initWithKey:(key) ascending:(bool)
key 为集合某对象的一个属性
bool YES 升序
NO 降序
集合调用sortUsingDescriptors:方法
参数为数组,这说明可以传入多个属性进行排序
1 NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES]; 2 NSArray *descriptors = [NSArray arrayWithObject:descriptor]; 3 NSArray *myDataArray = [NSArray arrayWithObjects:@"what", @"xero", @"highligth", @"mountain", @"Victory", @"Balance", nil]; 4 NSArray *resultArray = [myDataArray sortedArrayUsingDescriptors:descriptors]; 5 NSLog(@"%@", resultArray);

浙公网安备 33010602011771号