美文网首页
iOS block的写法

iOS block的写法

作者: FancyMF | 来源:发表于2019-06-18 15:16 被阅读0次

    How Do I Declare A Block in Objective-C?

    ```

    这是我的代码

    ```

    As a local variable:

    ```objc

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

    ```

    As a property:

    ```

    @property (nonatomic, copy, nullability) returnType (^blockName)(parameterTypes);

    ```

    As a method parameter:

    ```

    - (void)someMethodThatTakesABlock:(returnType (^nullability)(parameterTypes))blockName;

    ```

    As an argument to a method call:

    ```

    [someObject someMethodThatTakesABlock:^returnType (parameters) {...}];

    ```

    As a parameter to a C function:

    void SomeFunctionThatTakesABlock(returnType (^blockName)(parameterTypes));

    As a typedef:

    typedef returnType (^TypeName)(parameterTypes);

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

    转载来自  http://fuckingblocksyntax.com/

    相关文章

      网友评论

          本文标题:iOS block的写法

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