核心数据瞬态计算属性
我有一个包含lastName 和firstName 属性的实体。由于超出此问题范围的原因,我想要一个 fullName 属性,该属性作为firstName + space + lastName 的串联来计算。
因为这纯粹是一个计算值,不需要重做/撤消或瞬态属性的任何其他更复杂的方面(合并等),所以我的直觉告诉我只需重写 getter 方法即可返回所述计算值。阅读表明,如果我这样做,我唯一关心的是它是否符合 KVO,我可以通过使用 keyPathsForValuesAffectingVolume 来解决这个问题,以确保对firstName或lastName的更改为观察fullName的任何人触发通知。
我错过了什么吗?我正在检查,因为我是这个环境的初学者。
I have an entity that contains lastName and firstName attributes. For reasons beyond the scope of this question, I want a fullName attribute that gets calculated as a concatenation of firstName + space + lastName.
Because this is purely a calculated value, with no need for redo/undo or any other of the more sophisticated aspects of transient attributes (merging, etc.), my gut tells me to just override the getter method to return said calculated value. Reading suggests that, if I do this, my only concern would be whether it's KVO compliant, which I can address by using keyPathsForValuesAffectingVolume to ensure changes to firstName or lastName trigger notifications for anyone observing on fullName.
Am I missing anything? I'm checking because I'm a beginner to this environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此也很陌生,所以我不完全确定我的答案,但据我了解,你是对的。
I'm also new to this, so I'm not completely sure about my answer, but as I understand it you are correct.