• 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
Re: performSelector: question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: performSelector: question


  • Subject: Re: performSelector: question
  • From: "John C. Warner" <email@hidden>
  • Date: Tue, 27 Jul 2004 11:50:42 -0400

NSSelectorFromString(NSString *aSelectorName) is probably better. "Returns the selector named by aSelectorName, or 0 if none by this name exists."

<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ ObjC_classic/Functions/FoundationFunctions.html#//apple_ref/doc/uid/ 20000055/BCIEICGB>

-John

On Jul 27, 2004, at 11:34 AM, Bruce Truax wrote:

I am writing a parser for test input strings. Each string starts with a
keyword and is followed by 0 or more text or numeric arguments. I thought a
nice way to handle the processing of each string would be to create methods
with the same names as each keyword. I would then extract the keyword from
the string and call the method with that name passing the rest of the string
as an argument. The NSObject documentation describes the performSelector:
withObject method which would appear to do the job. The documentation
describes two ways to call this method:


id myClone = [anObject performSelector:@selector(copy)];

id myClone = [anObject performSelector:sel_getUid("copy")];

It would appear that the second method would work if I extracted the keyword
as follows:

id myClone = [anObject performSelector:sel_getUid([keywordString cString])
withObject:[restOfString]];

Is this the proper way to call a method using a string name?

Bruce
_______________________________________________
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.
_______________________________________________
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.


References: 
 >performSelector: question (From: Bruce Truax <email@hidden>)

  • Prev by Date: Re: performSelector: question
  • Next by Date: Re: performSelector: question
  • Previous by thread: Re: performSelector: question
  • Next by thread: Re: performSelector: question
  • Index(es):
    • Date
    • Thread