Skip to content

Instantly share code, notes, and snippets.

@haikusw
Forked from bsneed/NSObject-extension.m
Created August 13, 2010 17:08
Show Gist options
  • Save haikusw/523212 to your computer and use it in GitHub Desktop.
Save haikusw/523212 to your computer and use it in GitHub Desktop.
/*
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