• 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
RS: going from the name of a method to the method itself
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: RS: going from the name of a method to the method itself
      • From: Scott Ribe <email@hidden>
    • Re: RS: going from the name of a method to the method itself
      • From: mmalc crawford <email@hidden>
    • Re: RS: going from the name of a method to the method itself
      • From: Jayson Adams <email@hidden>
  • Prev by Date: Re: How to track a lost mouseDown
  • Next by Date: NSTask setStandardOutput: then stringWithContentsOfFile gives empty string
  • Previous by thread: Re: How to track a lost mouseDown
  • Next by thread: Re: RS: going from the name of a method to the method itself
  • Index(es):
    • Date
    • Thread