例如常用的方法:
将数组按key 排序 yesorno 为是否按顺序还是逆序
+ (void) changeArray:(NSMutableArray *)dicArray orderWithKey:(NSString *)key ascending:(BOOL)yesOrNo{
NSSortDescriptor *distanceDescriptor = [[NSSortDescriptor alloc] initWithKey:key ascending:yesOrNo];
NSArray *descriptors = [NSArray arrayWithObjects:distanceDescriptor,nil];
[dicArray sortUsingDescriptors:descriptors];
[distanceDescriptor release];
}
NSSortDescriptor *bySpell = [NSSortDescriptor sortDescriptorWithKey:@"spell" ascending:YES];
_cities = [[NSArray arrayWithContentsOfFile:cityPlistPath] sortedArrayUsingDescriptors:@[bySpell]];
根据spell按照顺序排序。