Skip to content

Instantly share code, notes, and snippets.

@kyktommy
Last active December 27, 2015 20:39
Show Gist options
  • Save kyktommy/7386200 to your computer and use it in GitHub Desktop.
Save kyktommy/7386200 to your computer and use it in GitHub Desktop.
objc block take the responsibility in current scope
typedef NSString* (^ConfigureNameBlock)(NSString *firstName, NSString *lastName);
- (void) runBlock
{
NSString *suffix = @"i am in your back";
NSString *(^configureName)(NSString *, NSString *) = ^(NSString *firstName, NSString *lastName) {
return [NSString stringWithFormat: @"%@, %@, %@", firstName, lastName, suffix];
};
NSLog(@"%@", [self displayName:@"peter" configureName:configureName]);
// => peter, is the best of the world, i am in your back
}
- (NSString *)displayName: (NSString *) firstName
configureName: (ConfigureNameBlock) aConfigureBlock
// configureName: (NSString *(^)(NSString *firstName, NSString *lastName)) aConfigureBlock
{
return aConfigureBlock(firstName, @"is the best of the world");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment