Can I use Objective-C blocks as properties?

gurghet picture gurghet · Oct 14, 2010 · Viewed 117.9k times · Source

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

Are there any changes for ARC?

Answer

Robert picture Robert · Oct 23, 2012
@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;