Last active
August 24, 2016 11:37
-
-
Save n-b/010dcdf4ead6b6cd7b29 to your computer and use it in GitHub Desktop.
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
#!/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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's clever!