我可以根据Objective-C中的键sortingNSDictionary吗?

我可以根据关键字sortingNSDictionary吗?

您可以对键进行sorting,然后通过遍历它们来创build一个NSMutableArray

 NSArray *sortedKeys = [[dict allKeys] sortedArrayUsingSelector: @selector(compare:)]; NSMutableArray *sortedValues = [NSMutableArray array]; for (NSString *key in sortedKeys) [sortedValues addObject: [dict objectForKey: key]]; 

使用objectsForKeys:notFoundMarker:非常简单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:@""];