Skip to content

Instantly share code, notes, and snippets.

@hechien
Created July 4, 2011 03:34
Show Gist options
  • Save hechien/1062874 to your computer and use it in GitHub Desktop.
Save hechien/1062874 to your computer and use it in GitHub Desktop.
Objective-C Block in C function and Object.
@interface Worker : NSObject {
}
+(void)something:(void (^)(BOOL))block;
@end
@implementation Worker
+(void)something:(void (^)(BOOL))block{
block(YES);
}
@end
void exec(void (^run)(BOOL)){
NSLog(@"In exec");
run(NO);
}
void (^run_to_me)(BOOL) = ^(BOOL lonely){
if(lonely) NSLog(@"whenever you're lonely");
else NSLog(@"f**k off");
};
run_to_me(YES);
exec(run_to_me);
run_to_me(NO);
[Worker something:run_to_me];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment