• 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: Erik Stainsby <email@hidden>
  • Date: Tue, 31 Jul 2012 22:20:56 -0700

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 … ?


On 2012-07-31, at 10:13 PM, Graham Cox <email@hidden> wrote:

>
> On 01/08/2012, at 3:07 PM, Graham Cox wrote:
>
>> NSSortDescriptor* desc = [NSSortDescriptor sortDescriptorWithKey:@"compare:" ascending:YES];
>
>
> Oops, this wasn't what I meant.
>
> The "key" should be the property you're comparing to sort the objects. If your array is a bunch of strings to be sorted, then what is the key? Well, it's actually "self":
>
> NSSortDescriptor* desc = [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES];
>
> Because internally the descriptor is looping over the array and doing a -valueForKey:@"self" on each object, and that returns the object itself. The sort comparison itself is done by invoking -compare: on the objects.
>
>
> If it's another sort of object that has a string property, then you would pass the name of that property, e.g. @"lastName".
>
> --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


  • Follow-Ups:
    • Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
      • From: Graham Cox <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>)

  • Prev by Date: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • Next by Date: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • Previous by thread: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • Next by thread: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • Index(es):
    • Date
    • Thread