Create a gist now

Instantly share code, notes, and snippets.

@n-b /Blocks.m
Last active Aug 24, 2016

What would you like to do?
#!/usr/bin/env objc-run
@import Foundation;
@interface NSBlock // bite me
@implementation NSBlock (invoke)
- (void) invoke
((void (^)(void))self)();
int main() {
void (^foo)(void) = ^{ NSLog(@"yolo"); };
void (^bar)(void) = nil;
bar(); // <- this crashes
[foo invoke];
[bar invoke]; // <- this doesn’t

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