Last active
May 1, 2017 12:05
-
-
Save TechMaster/807242c3024ad2fea8d429c8379d98ea to your computer and use it in GitHub Desktop.
Recursive Block Call
This file contains hidden or 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) printString: (NSString*) msg | |
| onComplete: (void (^)(void)) complete{ | |
| NSLog(@"%@", msg); | |
| complete(); | |
| } | |
| -(void) demoRecursiveBlock | |
| { | |
| __block int index = 0; | |
| NSArray* array = @[@"ABC", @"DEF", @"MNP"]; | |
| __block __weak void (^weak_Complete)(void); | |
| __block __strong void (^strong_Complete)(void) ; | |
| weak_Complete = strong_Complete = ^{ | |
| index++; | |
| NSLog(@"%d", index); | |
| if (index == array.count) return; | |
| NSString* str = array[index]; | |
| [self printString:str onComplete:weak_Complete]; | |
| }; | |
| NSString* str = array[index]; | |
| [self printString:str onComplete: strong_Complete]; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment