ARC forbids synthesizing a property with unspecifi

2019-03-23 04:12发布

问题:

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).