Ios – use Objective-C blocks as properties

automatic-ref-countingiosobjective cobjective-c-blocks

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

Are there any changes for ARC?

Best Answer

@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;