RS: going from the name of a method to the method itself
RS: going from the name of a method to the method itself
- Subject: RS: going from the name of a method to the method itself
- From: Roland Silver <email@hidden>
- Date: Mon, 27 Aug 2007 13:42:08 -0600
Question: If I know the NAME of a method (as an NSString*) which one
argument (an NSString*), how do I invoke that method with that arg?
I tried this, but it doesn't work:
- (void) foo:(NSString*)arg {
NSLog(@"%@", arg); }
...
NSString* methodName = @"foo";
NSString* arg = @"gotcha?;
id methodSelector = NSSelectorFromString(methodName);
[methodSelector arg];
How do I apply the method named @"foo" to the string arg = @"gotcha?"
I know I can just do [foo arg], but suppose I don't have the
implementation of foo, but only its name?
I've read everything I could lay my hands on about SEL and @select
(ADC documentation, Hillegass, Google), but I can't figure out the
answer to my question from any of those sources.
What kind of thing is an NSSelector, anyway? Is it an object?
If I declare something with SEL, what kind of thing is it that I've
declared?
-- Roland Silver <email@hidden>
_______________________________________________
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