PDA

View Full Version : NSDictionary and .plist file keys appear unordered?




Soulstorm
Oct 25, 2009, 10:32 AM
I am using "+ (id)dictionaryWithContentsOfFile:(NSString *)path" to load contents from a .plist file inside my application bundle. Although the contents are parsed correctly, the keys are unordered.

For example, if I give the command "allKeys", I will get an NSArray that contains my dictionary objects inside the .plist file.

However, I will get the array with a set of keys with different order than the one I have written in the .plist file.

Is that how it is supposed to be? Am I doing something wrong? I am using Property List Editor to make the .plist file.



PhoneyDeveloper
Oct 25, 2009, 11:36 AM
allKeys
Returns a new array containing the receiverís keys.

- (NSArray *)allKeys

Return Value
A new array containing the receiverís keys, or an empty array if the receiver has no entries.

Discussion
The order of the elements in the array is not defined.

firewood
Oct 25, 2009, 01:06 PM
If you want things ordered, you should use an array instead of a dictionary.

Soulstorm
Oct 26, 2009, 03:18 PM
allKeys
Returns a new array containing the receiverís keys.

- (NSArray *)allKeys

Return Value
A new array containing the receiverís keys, or an empty array if the receiver has no entries.

Discussion
The order of the elements in the array is not defined.

You can't imagine how much I laughed after I read this. My bad. Sorry.