iosobjective-cautomatic-ref-countingobjective-c-blocks

Can I use Objective-C blocks as properties?


Is it possible to have blocks as properties using the standard property syntax?

Are there any changes for ARC?


Solution

  • @property (nonatomic, copy) void (^simpleBlock)(void);
    @property (nonatomic, copy) BOOL (^blockWithParamter)(NSString *input);
    

    If you are going to be repeating the same block in several places use a type def

    typedef void(^MyCompletionBlock)(BOOL success, NSError *error);
    @property (nonatomic) MyCompletionBlock completion;