hmhmsh
11/30/2017 - 5:13 AM

How to write block of Objective-C

// 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");
}
// 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");
}