Declare a block method parameter without using a typedef

前端 未结 5 630
感情败类
感情败类 2020-12-04 05:13

Is it possible to specify a method block parameter in Objective-C without using a typedef? It must be, like function pointers, but I can\'t hit on the winning syntax witho

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 06:13

    Even more clear !

    [self sumOfX:5 withY:6 willGiveYou:^(NSInteger sum) {
        NSLog(@"Sum would be %d", sum);
    }];
    
    - (void) sumOfX:(NSInteger)x withY:(NSInteger)y willGiveYou:(void (^) (NSInteger sum)) handler {
        handler((x + y));
    }
    

提交回复
热议问题