__block attribute on property declarations

只谈情不闲聊 提交于 2019-12-03 20:40:16

I'll suggest you've found a compiler bug, the declaration:

@property (nonatomic, retain) __block id myProperty;

is meaningless. The __block qualifier is used on local (stack allocated) variables so they are passed by reference to blocks, so they can be updated, and are usually[*] stored on the heap rather than the stack.

Therefore the qualifier __block has no meaning on a property declaration which is concerned with object instances, which are heap allocated at all times in Obj-C.

Just drop the __block from the property declarations - for every compiler.

[*] If a block is never copied to the heap a compiler may optimize __block variables and not move those to the heap either.

just before you use the variable in a block, create a local pointer of type __block. Don't ever use __block in @property declarations.

EG: TypeOfVariable __block *bock_pointer = self.property;

^{ inside the block use bock_pointer }

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