Does @property (readonly, retain) have a meaning?

▼魔方 西西 提交于 2019-12-11 08:59:16

问题


XCode accepts it. But will retain be applied when I internally set the property (no setter outside since readonly but when I initialize the value in a class method) ?

Regards, Apple92


回答1:


The reason to do this is to allow you to do @property (retain) in a class continuation or category. If you don't have the retain on the outer property, you will get a warning about the properties being mismatched.




回答2:


You might specify (readonly, retain) for a publicly-facing property, and then inside your .m, re-define it as (readwrite, retain) to be able to assign to it privately. I use this pattern myself occasionally.




回答3:


it's also nice as a form of interface documentation



来源:https://stackoverflow.com/questions/3894888/does-property-readonly-retain-have-a-meaning

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