Re: How to use "SEL"
Re: How to use "SEL"
- Subject: Re: How to use "SEL"
- From: Sherm Pendley <email@hidden>
- Date: Wed, 9 Oct 2002 02:21:25 -0400
On Wednesday, October 9, 2002, at 01:48 AM, Ken Tozier wrote:
// Is this the right way to get a selector for a hypothetical "doFoo"
method?
SEL theMethodSelector = [self selector:@selector( doFoo: )];
It depends. If the selector name is hard-wired into your code:
SEL theMethodSelector = @selector(doFoo:);
If you need more flexibility, you can create a selector from a string:
NSString *selName = @"doFoo:";
SEL theMethodSelector = NSSelectorFromString(selName);
If you need yoga-master flexibility, take a look at the NSInvocation
class.
// and once I have the "SEL", I'd like to use it as follows
- (id) newWidget:(SEL) inSelector
{
// to actually use the selector what do I do?
[self **** ????****];
[self performSelector: inSelector];
Note that selectors are not "attached" to a particular class, as your
example above would imply. Any selector can be sent to any class or
object - keeping in mind, of course, that if the target doesn't
implement the corresponding method, an "unrecognized selector" warning
will be logged.
sherm--
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.