ARC禁止合成具有未指定所有权或存储的属性 [英] ARC forbids synthesizing a property with unspecified ownership or storage
问题描述
我创建了 @property
UIColor
,
@property (nonatomic) UIColor *color;
然后我尝试合成它:
@synthesize color = _color;
但我收到一个错误:
ARC禁止合成具有未指定的所有权或存储属性的Objective-C对象的属性
ARC forbids synthesizing a property of Objective-C object with unspecified ownership or storage attribute
?
所有我想做的是为一个 UIColor
对象创建一个属性, / p>
All I'm trying to do is to create a property for a UIColor
object which changes color.
推荐答案
将您的资源声明更改为:
Change your property declaration to:
@property(nonatomic,strong)UIColor * color;
,以便ARC知道应该保留。这将编译没有 strong
之前的ARC,但它是危险的,因为默认是 assign
,颜色将已经
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.
我强烈推荐关于ARC的WWDC2011视频。
I would highly recommend the WWDC2011 video about ARC.
这篇关于ARC禁止合成具有未指定所有权或存储的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!