assign properties, ARC and Core Foundation objects

人走茶凉 提交于 2019-11-27 20:56:28

If you're using the automatically synthesized getters and setters, there is indeed a memory management problem here. In the setter, your CGColor needs to be released and the new value retained, but the assign accessor will not do this for you — it literally just assigns the new pointer value to the variable. You'll need to implement your own accessors in order to manage the memory correctly.

However, if you'd like, ARC can handle this for you instead of you having to do it yourself. Just declare it like so:

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