我需要能够排序我的排序方法的结果,但我不清楚如何做到这一点,我是否需要再次运行一个相似的方法对以前的结果或可以它用一种方法完成?排序结果Obj-c
这里是我的方法
-(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;
}
类型被设置为返回在我游戏中的所有建筑类型,但如果我再想这些结果按照他们的名字字母顺序进行排序“大厦”?或者可能根据哪个建筑物的黄金价值来排序最高?
对,所以这只是一个通过数组进行多次扫描的问题,方法稍有不同。 – Phil 2013-04-27 15:06:48
是的。但是你的复杂性实际上并没有增加,所以成本并不令人望而却步。祝你好运! – QED 2013-04-27 15:07:47