• 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: how to simulate passing parameter with selector
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to simulate passing parameter with selector


  • Subject: Re: how to simulate passing parameter with selector
  • From: Adam P Jenkins <email@hidden>
  • Date: Thu, 14 Feb 2008 02:07:23 -0500


On Feb 13, 2008, at 8:36 PM, Daniel Child wrote:

I'm sorry, but looking at the documentation I don't see how using NSSortDescriptor works.

I agree I don't think NSSortDescriptor would be useful in this case, since you want to sort on an array index rather than on a selector. However several people have also mentioned the sortedArrayUsingFunction:context: method of NSArray, which will allow you to do what you want. You'd use it something like this:


NSArray *arrayOfArrays = [create array of arrays];
int column = 2;   // sort on column 2

NSInteger compare(id a, id b, void *context) {
  int column = *((int*)context);

  compare [a objectAtIndex:column] and [b objectAtIndex:column]
}

NSArray *sorted = [arrayOfArrays sortedArrayUsingFunction:compare context:&column];

_______________________________________________

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: how to simulate passing parameter with selector
      • From: Daniel Child <email@hidden>
References: 
 >how to simulate passing parameter with selector (From: Daniel Child <email@hidden>)
 >Re: how to simulate passing parameter with selector (From: "Hamish Allan" <email@hidden>)
 >Re: how to simulate passing parameter with selector (From: Daniel Child <email@hidden>)

  • Prev by Date: Re: KVC and KVO for arrays
  • Next by Date: Observing with NSDictionarycontroller
  • Previous by thread: Re: how to simulate passing parameter with selector
  • Next by thread: Re: how to simulate passing parameter with selector
  • Index(es):
    • Date
    • Thread