[cfe-dev] ARC and @synthesize of read only property

Chris Lattner clattner at apple.com
Tue Jul 19 19:04:17 PDT 2011

On Jul 19, 2011, at 11:46 AM, Jean-Daniel Dupas wrote:

> When I'm trying to synthesize a read only property in obj-c, I get the following error.
> error: ARC forbids synthesizing a property of an Objective-C object with unspecified storage attribute [4]
> I understand why it is necessary to specify storage attribute to generate a setter, but why is it relevant to generate a getter ? 
> Just in case, here is a simple test case:
> @interface Foo { id _ivar; }
> @property(nonatomic, readonly) id ivar;

The simple answer is that this code defaulted to being an "assign" property before, and that dangerous because it quickly leads to a dangling pointer.  ARC forces you to make a choice: strong, weak, unsafe_unretain, etc.


More information about the cfe-dev mailing list