【发布时间】:2013-04-27 14:24:25
【问题描述】:
我需要能够对我的 sort 方法的结果进行排序,但我不清楚如何做到这一点,我是否需要对以前的结果再次运行一个类似的方法,还是可以用一种方法完成?
这是我的方法
-(NSArray*)getGameTemplateObjectOfType:(NSString *) type
{
NSArray *sortedArray;
if(editorMode == YES)
{
sortedArray = kingdomTemplateObjects;
}
else
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"type CONTAINS[cd] %@", type];
NSArray *newArray = [kingdomTemplateObjects filteredArrayUsingPredicate:predicate];
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:type
ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
sortedArray = [newArray sortedArrayUsingDescriptors:sortDescriptors];
}
return sortedArray;
}
type 被设置为“Building”,它返回我游戏中的所有建筑类型,但如果我希望这些结果按照名称按字母顺序排序怎么办?或者也许按照哪个建筑的黄金价值最贵来排序?
【问题讨论】:
标签: objective-c