キーに基づいてNSDictionary
をソートできますか?
キーを並べ替えてから、それらを反復処理してNSMutableArray
を作成できます。
NSArray *sortedKeys = [[dict allKeys] sortedArrayUsingSelector: @selector(compare:)];
NSMutableArray *sortedValues = [NSMutableArray array];
for (NSString *key in sortedKeys)
[sortedValues addObject: [dict objectForKey: key]];
objectsForKeys:notFoundMarker:
を使用する方がはるかに簡単です
NSDictionary *yourDictionary;
NSArray *sortedKeys = [yourDictionary.allKeys sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES]]];
// As we using same keys from dictionary, we can put any non-nil value for the notFoundMarker, because it will never used
NSArray *sortedValues = [yourDictionary objectsForKeys:sortedKeys notFoundMarker:@""];