Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
#!/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

This comment has been minimized.

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