PDA

View Full Version : NSDictionary puts items in screwy order?!?




mpemburn
Jul 8, 2009, 06:56 AM
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



ChOas
Jul 8, 2009, 07:04 AM
Hi Folks,


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

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.

gnasher729
Jul 8, 2009, 07:08 AM
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?

I'm pretty sure you didn't read the NSString documentation. Check out the compare: options: method.

mpemburn
Jul 9, 2009, 08:17 AM
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