Skip to content

Instantly share code, notes, and snippets.

@n-b
Last active August 24, 2016 11:37
Show Gist options
  • Save n-b/010dcdf4ead6b6cd7b29 to your computer and use it in GitHub Desktop.
Save n-b/010dcdf4ead6b6cd7b29 to your computer and use it in GitHub Desktop.
#!/usr/bin/env objc-run
@import Foundation;
@interface NSBlock // bite me
@end
@implementation NSBlock (invoke)
- (void) invoke
{
((void (^)(void))self)();
}
@end
int main() {
void (^foo)(void) = ^{ NSLog(@"yolo"); };
void (^bar)(void) = nil;
foo();
bar(); // <- this crashes
[foo invoke];
[bar invoke]; // <- this doesn’t
}
@mickeyl
Copy link

mickeyl commented Aug 24, 2016

That's clever!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment