ARC forbids synthesizing a property with unspecified ownership or storage

走远了吗. 提交于 2019-12-04 16:45:41

问题


I've created a @property of UIColor,

@property (nonatomic) UIColor *color;

and then I tried to synthesize it:

@synthesize color = _color;

but I receive an error:

ARC forbids synthesizing a property of Objective-C object with unspecified ownership or storage attribute

What does that mean?

All I'm trying to do is to create a property for a UIColor object which changes color.


回答1:


Change your property declaration to:

@property (nonatomic,strong) UIColor *color;

so that ARC knows it should be retained. This would have compiled without strong before ARC but it would be dangerous since the default was assign and the color would have been released unless it was retained elsewhere.

I would highly recommend the WWDC2011 video about ARC.




回答2:


You have to specify either strong or weak storage in the property declaration (next to nonatomic).



来源:https://stackoverflow.com/questions/8460611/arc-forbids-synthesizing-a-property-with-unspecified-ownership-or-storage

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