Created
April 19, 2012 10:18
-
-
Save aufflick/2420113 to your computer and use it in GitHub Desktop.
Turns out you can add methods to the block classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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