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 protected]> 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 protected]) 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 [email protected]
