Skip to content

Instantly share code, notes, and snippets.

@isutton
Created July 9, 2012 11:33
Show Gist options
  • Save isutton/3075958 to your computer and use it in GitHub Desktop.
Save isutton/3075958 to your computer and use it in GitHub Desktop.
NSInvocation usage example.
// Omitting the ownership qualification here can lead to a EXC_BAD_ACCESS exception in ARC enabled projects.
__weak id returnValue = nil;
SEL selector = @selector(colorFromString:);
NSString *valueString = @"0.2 0.2 0.2 1.0";
// Create and configure the NSInvocation object.
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[target methodSignatureForSelector:selector]];
invocation.selector = selector;
invocation.target = target;
[invocation setArgument:&valueString atIndex:2];
[invocation invoke];
[invocation getReturnValue:&returnValue];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment