Search code examples
objective-cmemory-managementdeclared-property

Why does a declared property use both retain and readonly?


I've noticed that some of Apple's examples include both a retain and readonly modifier on properties. What's the point of including retain if no setter gets generated when we're using the readonly modifier?

Example: @property (retain, readonly) NSString *title; from the AnimatedTableView sample.


Solution

  • You can include a second, private readwrite declaration in a class extension. The memory management scheme for all references needs to match IIRC, so you get silliness like "readonly, retain".