问题
I have a third party API that exposes an imageBlock
property. I am new to Blocks - how should I set this Block in my class?
@property (copy) NSString *(^imageBlock)(NSString *key, NSString *value, BOOL *send);
回答1:
Your syntax is correct, however, for sanity and readability I would recommend a typedef
to create another name for this Block signature:
// MyClass.h
typedef NSString * (^ImageBlock)(NSString * key, NSString * value, BOOL * send);
Your property declaration then becomes:
@property (copy) ImageBlock imageBlock;
and any other file which imports this header can see the typedef
, likewise using it to increase readability.
来源:https://stackoverflow.com/questions/8956921/setting-up-a-block-property-in-custom-class