-
-
Save haikusw/523212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
You can use this to call deprecated methods without warnings (supporting old sdk's for example) | |
or, you can use it in place of performSelector: where you need non-object params, or multiple | |
params. | |
*/ | |
- (void)callSelector:(SEL)aSelector returnAddress:(void *)result argumentAddresses:(void *)arg1, ... | |
{ | |
va_list args; | |
va_start(args, arg1); | |
if([self respondsToSelector:aSelector]) | |
{ | |
NSMethodSignature *methodSig = [[self class] instanceMethodSignatureForSelector:aSelector]; | |
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: methodSig]; | |
[invocation setTarget:self]; | |
[invocation setSelector:aSelector]; | |
if (arg1) | |
[invocation setArgument:arg1 atIndex:2]; | |
void *theArg = nil; | |
for (int i = 3; i < [methodSig numberOfArguments]; i++) | |
{ | |
theArg = va_arg(args, void *); | |
if (theArg) | |
[invocation setArgument:theArg atIndex:i]; | |
} | |
[invocation invoke]; | |
if (result) | |
[invocation getReturnValue:result]; | |
} | |
va_end(args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment