[cfe-dev] ARC and @synthesize of read only property
devlists at shadowlab.org
Tue Jul 19 13:06:37 PDT 2011
Le 19 juil. 2011 à 21:50, David Chisnall a écrit :
> On 19 Jul 2011, at 19:46, 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 
>> I understand why it is necessary to specify storage attribute to generate a setter, but why is it relevant to generate a getter ?
> The getter semantics also change:
> - If the property is retained, then it will retain / autorelease the object, to ensure that it is not deallocated prematurely.
> - If the property is weak, then it must use the weak read barrier function
> - If the property is unsafe_unretained, then the getter will just return it directly.
Thank you for the explanation. So the retained/autorelease is a new behavior introduced with ARC. AFAIK, the getter did this only for atomic properties in non ARC mode.
> Even in ARC mode, the compiler can't magically guess what you mean.
While it cannot always guess, when the @synthezise directive specify an ivar, it can default to the ivar ownership, as this is the only acceptable value.
More information about the cfe-dev