For general use (method with return value and any number of arguments) use NSInvocation :
if ([target respondsToSelector:theSelector]) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [target methodSignatureForSelector:theSelector]]; [invocation setTarget:target]; [invocation setSelector:theSelector]; // Note: Indexes 0 and 1 correspond to the implicit arguments self and _cmd, // which are set using setTarget and setSelector. [invocation setArgument:arg1 atIndex:2]; [invocation setArgument:arg2 atIndex:3]; [invocation setArgument:arg3 atIndex:4]; // ...and so on [invocation invoke]; [invocation getReturnValue:&retVal]; // Create a local variable to contain the return value. }
source share