Last active
December 27, 2015 20:39
-
-
Save kyktommy/7386200 to your computer and use it in GitHub Desktop.
objc block
take the responsibility in current scope
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
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