@property(只读,保留)有含义吗?
XCode 接受它。但是,当我内部设置该属性时(由于只读,但当我在类方法中初始化该值时,外部没有设置器),是否会应用保留?
问候, 苹果92
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以为面向公众的属性指定
(readonly, keep)
,然后在 .m 中将其重新定义为(readwrite, keep)
以便能够私下分配给它。我自己偶尔也会使用这种模式。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.这样做的原因是允许您在类延续或类别中执行
@property (retain)
。如果您没有保留外部属性,您将收到有关属性不匹配的警告。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.作为接口文档的一种形式也很好
it's also nice as a form of interface documentation