Created
July 16, 2010 21:18
-
-
Save CastIrony/478931 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
#define BLOCK(name, return, ...) return(^name)(__VA_ARGS__) | |
#define BLOCKTYPE(return, ...) return(^)(__VA_ARGS__) | |
// Example Usage: | |
// To declare a block inside a function/method: | |
// | |
// BLOCK(foo, int, BOOL) = ^(BOOL bar) { return bar ? 4 : 3; } | |
// | |
// NSLog(@"%d", foo(NO)); // "3" | |
// To write a method that returns one kind of block (which returns a NSDictionary*, and takes an NSArray* and a float) and takes | |
// another block (which returns an NSString* and takes an int and a bool) and you would write: | |
// | |
// -(BLOCKTYPE(NSDictionary*, NSArray*, float)) myMethodWithBlock:(BLOCKTYPE(NSString*, int, bool))myBlock | |
// | |
// Obviously that's a mess, and highly unlikely, but it's an example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment