Skip to content

Instantly share code, notes, and snippets.

@mako34
Created July 19, 2014 01:09
Show Gist options
  • Select an option

  • Save mako34/11d631754b8de24f9ff7 to your computer and use it in GitHub Desktop.

Select an option

Save mako34/11d631754b8de24f9ff7 to your computer and use it in GitHub Desktop.
iOS completion block
//define before implementation
typedef void(^myCompletion)(BOOL);
//method todo after implementation
-(void) myMethod:(myCompletion) compblock{
//do stuff
for (int i = 0; i < 100; i++) {
NSLog(@"i :: %d", i);
}
compblock(YES);
}
//caller of the method, knows when complete
[self myMethod:^(BOOL finished) {
if(finished){
NSLog(@"success");
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment