On 01/08/2012, at 3:20 PM, Erik Stainsby wrote:

> This has me thinking that to get the alpha sorted list of keys from a 
> dictionary I should be passing the keypath as the param for 
> sortDescriptorWithKey: and not trying to externalize the keys into an array 
> first … ?


If you want to iterate over the contents of a dictionary in alphabetical order 
of keys, I don't think there is a magic keypath that will allow you to operate 
on the dictionary itself.

Your first thought was right:

NSMutableArray  * sortedKeys =[ [dictionary allKeys] mutableCopy];
[sortedKeys sortUsingDescriptors:<descriptors>];                //<--- create 
descriptor using key @"self" or else using an alternative means of sorting

// now you can iterate over the dictionary in alphabetical order.


I would only use sort descriptors if a) I had to sort based on more than one 
criterion, e.g. lastName, firstName or b) I was using a table view that manages 
sorting using descriptors. For simple sorts there are easier ways to do it.


--Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to