CoreData 中的瞬态属性何时应包含在对象模型中?
我不确定瞬态属性的正确定义:
- 可以在对象模型中定义瞬态属性,然后在相关类需要时计算它们。
- 但是,如果您指定一个类并为任何瞬态属性定义任意 getter 方法,而无需在对象模型中声明它(只要该实体链接到模型中的该类),那么事情也同样有效。
我的问题:在对象模型中声明瞬态属性有什么好处? 我只看到一个缺点:每次添加瞬态属性(例如“FormattedDate”)时,持久存储都会变得不兼容。
我缺少什么?
I am unsure about the correct definition of transient properties:
- One can define transient properties in the object model and then calculate them when needed in the related class.
- But things work just as well if you specify a class and define arbitrary getter methods for any transient property without declaring it in the object model (as long as the entity is linked to that class in the model).
My question: What is the benefit of declaring transient properties in the object model?
I only see one down-side: each time you add a transient property (e.g. "FormattedDate") the persistentStore becomes incompatible.
what am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自核心数据编程指南:
我认为这意味着“方便”和“将所有属性定义在一个地方 - 托管对象模型”。
至于 MOM 版本控制,核心数据模型版本控制和数据迁移编程指南 说:
然而,它没有阐明其在瞬态属性上的立场。事实上,阐述该段落的第二个要点听起来几乎是一个矛盾。一个快速测试(带有一个带有“name”属性的简单“Foo”实体的新项目,保存一个包含多个foo的文件,添加一个瞬态属性,再次运行,并且foo全部加载,添加一个新的foo,保存,关闭,重新打开)显示版本控制系统实际上不考虑瞬态属性。
From the Core Data Programming Guide:
I take this to mean "convenience" and "keeping all your attributes defined in one place - the Managed Object Model".
As for MOM versioning, the Core Data Model Versioning and Data Migration Programming Guide says:
It doesn't clarify its position on transient properties, however. In fact the second bullet point elaborating that paragraph almost sounds like a contradiction. A quick test (new project with a simple "Foo" entity with a "name" attribute, save a file with several foos, add a transient property, run again, and the foos all load, add a new foo, save, close, re-open) shows transient properties in fact are not considered by the versioning system.