NSDictionary puts items in screwy order?!?

Discussion in 'Mac Programming' started by mpemburn, Jul 8, 2009.

  1. macrumors member

    Joined:
    Jan 11, 2008
    Location:
    Bel Air, MD USA
    #1
    Hi Folks,

    I have a PopupButton on my preferences window that's populated from a custom .plist. The items are entered in properly sorted order but when I pull them out, it looks like this:

    50 dpi
    450 dpi
    150 dpi
    1200 dpi
    75 dpi
    100 dpi
    200 dpi
    300 dpi
    600 dpi
    2400 dpi

    . . . which is just about random as far as I can tell. Now, I don't want to sort the list with an alpha sort because it'd come out like this:

    100 dpi
    1200 dpi
    150 dpi
    200 dpi
    2400 dpi
    300 dpi
    450 dpi
    50 dpi
    75 dpi
    600 dpi

    I'm pretty sure there's no "natural sort" mechanism built into Objective-C (which is why I pine for PHP at times like this). Is there any way to tell it to just leave it the heck alone?

    Thanks,

    -- Mark
     
  2. macrumors regular

    Joined:
    Nov 24, 2006
    Location:
    The Netherlands
    #2
    Keys are hashed, so there is no order guarantee.

    What you could do is keep an NSArray in order with the keys and do your NSDictionary lookups based on that.
     
  3. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #3
    I'm pretty sure you didn't read the NSString documentation. Check out the compare: options: method.
     
  4. thread starter macrumors member

    Joined:
    Jan 11, 2008
    Location:
    Bel Air, MD USA
    #4
    gnasher729 -- Thanks, I'll check it out. I've read parts of the documentation for many, many Objective-C classes over the past three months and that doesn't equate to a comprehensive knowledge. Don't have the leisure (or focus) to sit and read the whole thing from start to finish.

    -- Woody
     

Share This Page