Block 的声明方式

原文链接:How Do I Declare A Block in Objective-C?

  • 局部变量

    returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...};
  • 属性

    @property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);
  • 方法参数

    - (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName;
  • 方法调用的参数

    [someObject someMethodThatTakesABlock:^returnType (parameters) {...}];
  • C函数的参数

    void SomeFunctionThatTakesABlock(returnType (^blockName)(parameterTypes));
  • 类型定义

    typedef returnType (^TypeName)(parameterTypes);
    TypeName blockName = ^returnType(parameters) {...};

Title: Block 的声明方式

Date: 2019.03.10

Author: zhangpeng

Github: https://github.com/fullstack-zhangpeng