Created
July 4, 2011 03:34
-
-
Save hechien/1062874 to your computer and use it in GitHub Desktop.
Objective-C Block in C function and Object.
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
@interface Worker : NSObject { | |
} | |
+(void)something:(void (^)(BOOL))block; | |
@end | |
@implementation Worker | |
+(void)something:(void (^)(BOOL))block{ | |
block(YES); | |
} | |
@end |
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
void exec(void (^run)(BOOL)){ | |
NSLog(@"In exec"); | |
run(NO); | |
} |
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
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