Does an Objective-C readonly property need to specify strong or copy?

孤街浪徒 提交于 2019-12-04 01:01:46

问题


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;

回答1:


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.



来源:https://stackoverflow.com/questions/9405211/does-an-objective-c-readonly-property-need-to-specify-strong-or-copy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!