Skip to content

Instantly share code, notes, and snippets.

@PsychoH13
Created August 5, 2013 17:57
Show Gist options
  • Save PsychoH13/6157991 to your computer and use it in GitHub Desktop.
Save PsychoH13/6157991 to your computer and use it in GitHub Desktop.
Invoke a block using NSInvocation
#import <Foundation/Foundation.h>
int main(int argc, char **argv)
{
@autoreleasepool
{
void (^testBlock)(NSString *test) =
^(NSString *test)
{
NSLog(@"%@", test);
};
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:"v@?@"]];
[invocation setTarget:testBlock];
NSString *test = @"Hello, World!";
[invocation setArgument:&test atIndex:1];
[invocation invoke];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment