iOS Block一些有趣的东西

2018-06-06  本文已影响0人  本本的开心牧场

block的传递
typedef void(^Success)(int a,int b);

- (void)viewDidLoad {
    [super viewDidLoad];
    [self post:1 Success:^(int a, int b) {
        NSLog(@"a = %d",a);
        NSLog(@"b = %d",b);
        NSLog(@"---输出%d",a + b);
    }];
}

- (void)post:(BOOL)isPost Success:(Success)success {
    switch (isPost) {
        case 0:
            NSLog(@"失败了");
            break;
        case 1:
            NSLog(@"成功");
            [self Sucess:success];
            break;
        default:
            break;
    }
    
    
}

- (void)Sucess:(Success)success {
    if (success) {
        success(10,20);
    }
    
}
上一篇下一篇

猜你喜欢

热点阅读