how to simulate passing parameter with selector
how to simulate passing parameter with selector
- Subject: how to simulate passing parameter with selector
- From: Daniel Child <email@hidden>
- Date: Wed, 13 Feb 2008 15:51:43 -0500
Hi,
I am trying to work around the fact that you cannot pass parameter
values with a selector. Here's what I'm trying to do.
I have a generic table (essentially a class with an array instance
variable) filled with generic records (also a class containing an
array instance variable). I want to be able to sort the table based
on one of the fields in the generic record. Since the generic table
holds an array of records, my instinct is to use sortUsingSelector:
(SEL) s. The problem, of course, is that to set up compare methods, I
need to know which field I'm sorting on, and that is only determined
at runtime.
If you COULD send a parameter, the method call would look something
like:
- (void) sortTableOnField: (int) f {
....
[table records] sortUsingSelector: @selector(compareForFieldIndex: i)}
with the selector somehow transferring the index "i" (the array index
representing a particular field) so that comparisons can be made.
But (correct me if I'm wrong) you can't send arguments. And since
there could be tons of fields, writing out separate compare methods
(compareFieldOne, compareFieldTwo....) seems dumb.
Is there a way around this?
Thanks,
Daniel
_______________________________________________
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