ARC forbids synthesizing a property with unspecifi

2019-03-23 03:43发布

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.

2条回答
The star\"
2楼-- · 2019-03-23 04:24

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

查看更多
Juvenile、少年°
3楼-- · 2019-03-23 04:38

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.

查看更多
登录 后发表回答