How to write an Objective-C Completion Block

后端 未结 5 2051
萌比男神i
萌比男神i 2020-12-01 01:45

I\'m in a situation where need to call a class method from my view controller, have it do it\'s thing, but then perform some actions ONLY AFTER the class method has complete

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 02:31

    Regarding to http://goshdarnblocksyntax.com/

    As a local variable:

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

    As a property:

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

    As a method parameter:

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

    As an argument to a method call:

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

    As a typedef:

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

提交回复
热议问题