** 1st decision **
The solution is to mix the Objective-C runtime and NSMethodSignature functions .
First you need to include some headers
#include <objc/objc.h> #include <objc/objc-class.h> #include <objc/objc-runtime.h>
Then, wherever you want, starting with your selector, you get a parameter counter (note that each method has two implicit parameters self and _cmd , so you should not consider them to have only parameters):
SEL sel = @selector(performSelector:onThread:withObject:waitUntilDone:); Method m = class_getInstanceMethod([NSObject class], sel); const char *encoding = method_getTypeEncoding(m); NSMethodSignature *signature = [NSMethodSignature signatureWithObjCTypes:encoding]; int allCount = [signature numberOfArguments];
** Second Solution **
Convert the selector to NSString and count the ":" characters. Not sure if it is reliable.
source share