Re: Programmatically determining number of arguments a selector takes
Re: Programmatically determining number of arguments a selector takes
- Subject: Re: Programmatically determining number of arguments a selector takes
- From: Damien Bobillot <email@hidden>
- Date: Fri, 3 Jun 2005 16:43:19 +0200
Le 3 juin 05 à 15:36, glenn andreas a écrit :
On Jun 3, 2005, at 3:30 AM, Andrew White wrote:
I have some callback code that requires the user to pass in a
selector. I'd like to validate that the selector is of the correct
form - it must take exactly one argument.
I've searched through the doco and have not been able to find a
function that will tell me how many args an object of type SEL
requires. Does something like this exist?
You could look through the selector as a string and count the
number of ":" (technically, this works based entirely on the syntax
of Objective-C - nothing in the runtime enforces this - a selector
is basically just string).
You can also have a look to Objective-C introspection API :
http://developer.apple.com/documentation/Cocoa/Reference/
ObjCRuntimeRef/index.html
Look at the function : Method class_getInstanceMethod(Class aClass,
SEL aSelector)
Given a Class object and a selector, it returns a method descriptor
which contains the exact method signature : number of parameters,
parameter types and return type (with method_getArgumentInfo() and
method_getNumberOfArguments()).
--
Damien Bobillot
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden