performSelector: question
performSelector: question
- Subject: performSelector: question
- From: Bruce Truax <email@hidden>
- Date: Tue, 27 Jul 2004 11:34:48 -0400
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.