可能重複:
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