block

作者: 火鸡蛋大爷 | 来源:发表于2016-07-13 11:46 被阅读0次

    ///变量

    @property (nonatomic,copy,nullable) int (^blockName2) (int,int);

    self.blockName2 = ^ int (int a,int b){

    return a+b;

    };

    int a = self.blockName2(2,3);

    ///定义成参数

    int (^blockName)(int) = ^ int (int a){

    a += 10;

    NSLog(@"block");

    return a;

    };

    [self methodBlock:blockName];

    [self methodBlock:^int(int a) {

    a+=20;

    NSLog(@"block2");

    return a;

    }];

    ///当成参数传来

    -(void)methodBlock:(int (^)(int a)) blockName{

    int a =  blockName(2);

    NSLog(@"a=%d",a);

    }

    相关文章

      网友评论

          本文标题:block

          本文链接:https://www.haomeiwen.com/subject/tibsjttx.html