Created
May 30, 2016 20:55
-
-
Save commanda/250419ae9b386fa05e47bc38d3931507 to your computer and use it in GitHub Desktop.
A recursive block in Objective-C
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)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