In my interface (.h) file, I have
@property(readonly) NSString *foo;
and in my implementation (.m) file, I have
@synthesize foo;
With ARC turned on, the compiler gives me this error: Automatic Reference Counting Issue: ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute.
The error goes away if I add a strong
, weak
, or copy
to the property. Why is this? Why would there be any differences between these things for a read-only property, what are those differences, and why does the programmer have to worry about them? Why can’t the compiler intelligently deduce a default setting for a read-only property?
Another question while I’m at it: strong
, weak
, or copy
are the only things that make sense in ARC, right? I shouldn’t be using retain
and assign
anymore, should I?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…