Skip to content

Instantly share code, notes, and snippets.

@hmhmsh
Last active November 30, 2017 05:14
Show Gist options
  • Save hmhmsh/1fdf43e08683af6614e5951e2fa03b44 to your computer and use it in GitHub Desktop.
Save hmhmsh/1fdf43e08683af6614e5951e2fa03b44 to your computer and use it in GitHub Desktop.
// pattern1
-(void)a {
[self closure:^BOOL(int a, int b){
return a > b;
}];
}
-(void)closure:(BOOL(^)(int, int))close {
NSLog(@"%@", close(4,2) == 1?@"YES" : @"NO");
}
// pattern2
typedef bool (^myFunc)(int, int);
-(void)b {
myFunc fun = ^BOOL(int a, int b) {
return a > b;
};
[self closure:fun];
}
-(void)closure:(myFunc)close {
NSLog(@"%@", close(4,2) == 1?@"YES" : @"NO");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment