sort メソッドの結果をソートできるようにする必要がありますが、その方法がわかりません。前の結果に対してシミュレート メソッドを再度実行する必要がありますか、それとも 1 つのメソッドで実行できますか?
これが私の方法です
-(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" に設定され、ゲーム内のすべての建物の種類が返されますが、それらの結果を名前に従ってアルファベット順に並べ替えたい場合はどうすればよいでしょうか? または、金の価値からどの建物が最も高価であるかによってソートされますか?