Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LostSoul80

macrumors 68020
Original poster
Jan 25, 2009
2,136
7
Hi all,
how can i sort an NSArray containing NSDictionaries, wich contain NSNumber objects as a key, ascending by the keys?

Thanks
 

Bakerman

macrumors member
Jan 31, 2005
62
7
Sweden
Create a custom sort selector to do the comparison and use -[NSArray sortUsingSelector:]. It's probably not the fastest way to do it, but definitely the easiest.
 

LostSoul80

macrumors 68020
Original poster
Jan 25, 2009
2,136
7
I would look into:
http://developer.apple.com/DOCUMENT...cc/instm/NSArray/sortedArrayUsingDescriptors:

I just re-read what you said... and it seems like you want to sort by the keys not the values, which seems strange. Can you clarify what the keys look like?

-Lee

Hi, thanks for reply.
I was already using NSSortDescriptors, but such in a wrong way - i was having troubles because i hadn't realized NSNumber has a compare: method... so i was trying to create a custom comparison method, wich had had to convert the nsnumber into an nsstring to finally do the comparison, by calling -[NSString compare:string options:NSNumericSearch]. This makes me laugh. Sorry for this topic.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.