什么时候应该在对象模型中包含CoreData中的临时属性? [英] When should transient properties in CoreData be included in the object model?

查看:258
本文介绍了什么时候应该在对象模型中包含CoreData中的临时属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定临时属性的正确定义:

I am unsure about the correct definition of transient properties:


  1. 可以在对象模型中定义瞬态属性,

  2. 但是,如果您指定一个类并为任何瞬态属性定义任意的getter方法而不在对象模型中声明它,则事情也同样适用(只要实体在模型中链接到该类)。

我的问题:在对象模型中声明瞬态属性有什么好处?
我只看到一个缺点:每次添加一个瞬态属性(例如FormattedDate)persistentStore变得不兼容。

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.

我缺少什么?

推荐答案

核心数据编程指南


不支持的属性是一个对象,那么在受管对象模型中,您将其类型指定为undefined,并且它是瞬态的。当实现实体的自定义类时,不需要为该属性添加实例变量 - 您可以使用受管对象的私有内部存储。关于下面描述的实现的注意点是它们缓存瞬时值。这使得访问该值更有效 - 这对变更管理也是必要的。如果您定义自定义实例变量,应该在didTurnIntoFault而不是dealloc或finalize中清除这些变量。

If the non-supported attribute is an object, then in the managed object model you specify its type as undefined, and that it is transient. When you implement the entity’s custom class, there is no need to add an instance variable for the attribute—you can use the managed object's private internal store. A point to note about the implementations described below is that they cache the transient value. This makes accessing the value more efficient—it is also necessary for change management. If you define custom instance variables, you should clean up these variables in didTurnIntoFault rather than dealloc or finalize.

对于MOM版本控制,核心数据模型版本化和数据迁移编程指南说:

As for MOM versioning, the Core Data Model Versioning and Data Migration Programming Guide says:


Core Data对版本控制的看法是,它只对模型的影响持久性的特性感兴趣。

Core Data’s perspective on versioning is that it is only interested in features of the model that affect persistence.

然而,它并没有阐明它在瞬时属性上的位置。事实上,阐述该段落的第二个要点几乎听起来像一个矛盾。一个快速测试(新项目与一个简单的Foo实体具有名称属性,保存文件与几个foos,添加一个瞬态属性,再次运行,和foos所有加载,添加一个新的foo,保存,关闭,重新打开)显示临时属性实际上不被版本控制系统考虑。

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.

这篇关于什么时候应该在对象模型中包含CoreData中的临时属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆