Skip to content

Instantly share code, notes, and snippets.

@TechMaster
Last active May 1, 2017 12:05
Show Gist options
  • Select an option

  • Save TechMaster/807242c3024ad2fea8d429c8379d98ea to your computer and use it in GitHub Desktop.

Select an option

Save TechMaster/807242c3024ad2fea8d429c8379d98ea to your computer and use it in GitHub Desktop.
Recursive Block Call
-(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