Skip to content

Instantly share code, notes, and snippets.

@0xc010d
Created March 16, 2011 16:59
Show Gist options
  • Save 0xc010d/872834 to your computer and use it in GitHub Desktop.
Save 0xc010d/872834 to your computer and use it in GitHub Desktop.
+ (NSInvocation *)invocationWithTarget:(id)target action:(SEL)selector arguments:(NSArray *)arguments retainArguments:(BOOL)retainArguments {
NSMethodSignature *signature = nil;
if (isClass(target)) {
signature = [target methodSignatureForSelector:selector];
} else {
signature = [[target class] instanceMethodSignatureForSelector:selector];
}
NSInvocation *invocation = [self invocationWithMethodSignature:signature];
[invocation setTarget:target];
if (retainArguments) {
[invocation retainArguments];
}
NSInteger index = 2;
for (id argument in arguments) {
[invocation setArgument:&argument atIndex:index++];
}
return invocation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment