Skip to content

Instantly share code, notes, and snippets.

@commanda
Created May 30, 2016 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commanda/250419ae9b386fa05e47bc38d3931507 to your computer and use it in GitHub Desktop.
Save commanda/250419ae9b386fa05e47bc38d3931507 to your computer and use it in GitHub Desktop.
A recursive block in Objective-C
- (void)runRecursiveBlock
{
void(^ completionBlock) ();
void(^ __block __weak weakCompletionBlock) ();
weakCompletionBlock = completionBlock = ^{
NSLog(@"%@", NSStringFromSelector(_cmd));
void(^ strongCompletionBlock)() = weakCompletionBlock;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
strongCompletionBlock();
});
};
completionBlock();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment