• 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: Using NSSortDescriptor to reverse sort an NSArray containing NSString objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using NSSortDescriptor to reverse sort an NSArray containing NSString objects


  • Subject: Re: Using NSSortDescriptor to reverse sort an NSArray containing NSString objects
  • From: Ken Thomases <email@hidden>
  • Date: Fri, 6 Jun 2008 14:05:27 -0500

On Jun 6, 2008, at 3:43 AM, George Stuart wrote:

NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey:nil ascending:NO selector:@selector(localizedCompare:)];
NSArray *sortedArray = [unsortedArray sortedArrayUsingDescriptors: [NSArray arrayWithObject:desc]];
[desc release];


That seems to work just fine... but I'm worried. I "guessed" at using the key of "nil" since I want the actual objects in the array to be the target for the @selector. Is it a fluke that this works? I don't want to rely on undefined behavior.

Hmm. Good question. You could use @"description" as the key to eliminate the uncertainty. Or maybe @"self".


Cheers,
Ken

_______________________________________________

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: Using NSSortDescriptor to reverse sort an NSArray containing NSString objects
      • From: Andrew Merenbach <email@hidden>
References: 
 >Using NSSortDescriptor to reverse sort an NSArray containing NSString objects (From: George Stuart <email@hidden>)

  • Prev by Date: Re: Regular Expressions?
  • Next by Date: RE: how to build c++ file and create its instance in anotherobjective-c class
  • Previous by thread: Using NSSortDescriptor to reverse sort an NSArray containing NSString objects
  • Next by thread: Re: Using NSSortDescriptor to reverse sort an NSArray containing NSString objects
  • Index(es):
    • Date
    • Thread