10

If I have a read-only string property, is it necessary to specify strong (or retain) or copy in the declaration? If I don't specify, is one of them assumed?

It seems to me the ownership attribute is only useful when you have a setter.

@property (nonatomic, readonly) NSString *name;
jscs
  • 63,694
  • 13
  • 151
  • 195
Boon
  • 40,656
  • 60
  • 209
  • 315

1 Answers1

16

That is mostly correct. For a readonly property, strong, retain, weak, and assign have no effect. But if you also declare the property elsewhere as readwrite (most frequently in an anonymous category in the .m), then the other modifiers need to match.

yuji
  • 16,695
  • 4
  • 63
  • 64
  • Good answer! But if the readonly property doesn't have a getter and is not redeclared as readwrite internally, strong should apply to the property too because it has an ivar now, is this correct? – Zack Zhu Aug 18 '16 at 00:25