In Javascript, for example, you can get the arity (the number of arguments a function is supposed to take) by simply func.length
. How can I get this information for a method in Objective-C?
views:
40answers:
2
+5
A:
NSMethodSignature
is awesome for all kind of reflection information.
SEL selector = @selector(foo:);
NSMethodSignature *sig = [someObj methodSignatureForSelector:selector]
int argCount = [sig numberOfArguments];
Squeegy
2010-08-26 02:58:23
+1
A:
From The Objective-C Runtime Reference
method_getNumberOfArguments
Returns the number of arguments accepted by a method.
unsigned method_getNumberOfArguments(Method method) Parameters method A pointer to a Method data structure. Pass the method in question. Return Value An integer containing the number of arguments accepted by the given method.
Conceited Code
2010-08-26 03:00:26
NSMethodSignature will probably do the job more easily.
zneak
2010-08-26 03:02:24