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

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


  • Follow-Ups:
    • Re: how to simulate passing parameter with selector
      • From: Peter Ammon <email@hidden>
    • Re: how to simulate passing parameter with selector
      • From: Ken Thomases <email@hidden>
    • Re: how to simulate passing parameter with selector
      • From: "Hamish Allan" <email@hidden>
  • Prev by Date: Re: NSTokenField bug in 10.5.2?
  • Next by Date: Re: Uncaught exceptions thrown by Cocoa documented anywhere?
  • Previous by thread: Re: input manager killing my app
  • Next by thread: Re: how to simulate passing parameter with selector
  • Index(es):
    • Date
    • Thread