美文网首页
ios block申明

ios block申明

作者: 西充小凡哥 | 来源:发表于2022-04-03 21:52 被阅读0次

    局部变量
    returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
    举例:

    int (^completion)(int a) = ^int(int a){
    // ...
    };
    属性
    @property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);
    举例:

    @property (nonatomic, copy, nonnull) int (^completion)(int);
    方法形参

    • (void)doSomethingWithBlock:(returnType (^nullability)(parameterTypes))blockName;
      举例:

    • (void) doSomethingWithCompletion:(int (^_Nullable)(int))blockName;
      方法实参
      [someObject doSomethingWithBlock:^returnType (parameters) {...}];
      举例:

    [a doSomethingWithCompletion:^int (int) {
    // ...
    }];
    类型定义
    typedef returnType (^TypeName)(parameterTypes);
    TypeName blockName = ^returnType(parameters) {
    // ...
    };
    举例:

    typedef int (^Handler)(int);
    Handler handler = ^int(int) {
    // ...
    };
    最后,Enjoy yourself!

    作者:coderanger
    链接:https://www.jianshu.com/p/a1aa24693f2e
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

    相关文章

      网友评论

          本文标题:ios block申明

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