• 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: Daniel Child <email@hidden>
  • Date: Thu, 14 Feb 2008 09:41:24 -0500

Thanks. Others suggested this and that's what I ended up doing. I think it would be helpful if Cocoa included some function that did allow you to pass parameters through the sort functions, however. My case can't be unique.

On Feb 14, 2008, at 2:07 AM, Adam P Jenkins wrote:


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: Adam P Jenkins <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>)
 >Re: how to simulate passing parameter with selector (From: Adam P Jenkins <email@hidden>)

  • Prev by Date: Re: KVC and KVO for arrays
  • Next by Date: Re: Changing up/down arrow behavior for NSTextField
  • 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