Re: how to simulate passing parameter with selector
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