Skip to content

Instantly share code, notes, and snippets.

@aufflick
Created April 19, 2012 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aufflick/2420113 to your computer and use it in GitHub Desktop.
Save aufflick/2420113 to your computer and use it in GitHub Desktop.
Turns out you can add methods to the block classes
void foo(id self, SEL _cmd);
void foo(id self, SEL _cmd)
{
NSLog(@"foo");
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString * flubber = @"flubber";
void (^barGlobal)(void) = ^{ NSLog(@"bar"); };
void (^barStack)(void) = ^{ NSLog(@"bar %@", flubber); };
class_addMethod([barGlobal class], @selector(foo), (IMP)foo, "v@:");
class_addMethod([barStack class], @selector(foo), (IMP)foo, "v@:");
class_addMethod([[barStack copy] class], @selector(foo), (IMP)foo, "v@:");
barGlobal();
[barGlobal foo];
[[barGlobal copy] foo];
barStack();
[barStack foo];
[[barStack copy] foo];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment