Setting up a block property in custom class

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:15:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!