Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect signature of selector

Tags:

objective-c

How can I check the signature of the selector, or whether the selector requires parameters or not?

E.g. I want to check whether the selector is of type
-(void) method
or
-(void) method:(id)param

like image 746
Egil Avatar asked Oct 05 '10 23:10

Egil


1 Answers

You can get a lot of information about a particular selector with the NSMethodSignature class:

id obj = ...
SEL selector = ...

NSMethodSignature *signature = [obj methodSignatureForSelector:selector];
NSUInteger args = [signature numberOfArguments];
int i;
for(i = 0; i < args; i++)
   printf("argument type at index %d: %c", i, [signature getArgumentTypeAtIndex:i]);
like image 93
Jacob Relkin Avatar answered Oct 23 '22 23:10

Jacob Relkin