分配@property的setter是如何实现的?
在将 ivar 分配给新值之前,setter 的实现是否首先检查新值是否与旧值不同?
是否有文档(或源代码)参考显示如何合成属性的所有不同排列(取决于属性,分配
、保留
等)?
Does the implementation of the setter first check if the new value is different than the old value before assigning the ivar to the new value?
Is there a documentation (or source code) reference that shows all the different permutations (depending on the attributes, assign
, retain
, etc.) of how a property is synthesized?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法想象分配设置器首先检查以前的值。这将完全浪费 CPU 周期,因为无论哪种方式结果都是相同的。该文档明确说明了各种属性的语义,但它没有准确地向您显示合成了哪些代码。
I can't imagine the assign setter checks previous values first. That would be a complete waste of CPU cycles, since the result will be the same either way. The documentation explicitly states the semantics of the various attributes, but it doesn't show you exactly what code is synthesized.
Objective-C 文档解释了这一点。实际发生的细节是特定于实现的。
...
...
The Objective-C documentation explains this. The details of what actually happens are implementation specific.
...
...