NSDictionary and .plist file keys appear unordered?

Discussion in 'iOS Programming' started by Soulstorm, Oct 25, 2009.

  1. Soulstorm macrumors 68000


    Feb 1, 2005
    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.
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    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.

    The order of the elements in the array is not defined.
  3. firewood macrumors 604

    Jul 29, 2003
    Silicon Valley
    If you want things ordered, you should use an array instead of a dictionary.
  4. Soulstorm thread starter macrumors 68000


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

Share This Page