• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?


  • Subject: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • From: Graham Cox <email@hidden>
  • Date: Wed, 01 Aug 2012 15:27:30 +1000

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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering? (From: Erik Stainsby <email@hidden>)
 >Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering? (From: Graham Cox <email@hidden>)
 >Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering? (From: Graham Cox <email@hidden>)
 >Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering? (From: Erik Stainsby <email@hidden>)

  • Prev by Date: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • Next by Date: Re: MKMapView annotation changes not being reflected on map display. Baffling.
  • Previous by thread: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • Index(es):
    • Date
    • Thread