Skip to content

Instantly share code, notes, and snippets.

@mikeash
Created September 30, 2011 19:07
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mikeash/1254684 to your computer and use it in GitHub Desktop.
dispatch_block_t RecursiveBlock(void (^block)(dispatch_block_t recurse))
{
// assuming ARC, so no explicit copy
return ^{ block(RecursiveBlock(block)); };
}
typedef void (^OneParameterBlock)(id parameter);
OneParameterBlock RecursiveBlock1(void (^block)(OneParameterBlock recurse, id parameter))
{
return ^{ block(RecursiveBlock1(block), parameter) };
}
use:
dispatch_block_t block = RecursiveBlock(^(dispatch_block_t recurse) {
if(!done)
recurse();
else
...
});
block();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment