NSDictionary and .plist file keys appear unordered?

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

  1. macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #1
    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. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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.
     
  3. macrumors 603

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

    Soulstorm

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

Share This Page