可能重复:
Can i sort the NSDictionary on basis of key in Objective-C?订购的NSDictionary allObjects通过按键
我有一个的.plist文件中的几个字符串,我试图返回到的NSDictionary,然后到一个数组,但返回的顺序与我保存在播放列表中的顺序不同。 到目前为止,我已经尝试
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *strs = [NSArray arrayWithArray:[dict allKeys]];
strs = [strs sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
但这仅仅是返回键名。
你不能订购一个NSDictionary,它是一个固有的无序对象。您可以像您一样对键进行排序,然后循环访问有序键以按照该顺序获取值,但仍然不排序字典。 – rdelmar
http://stackoverflow.com/questions/8829119/getting-values-as-in-order-they-added-with-nsdictionary – vikingosegundo