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

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

问题描述

我不确定瞬态属性的正确定义:

I am unsure about the correct definition of transient properties:


  1. 可以在对象模型中定义瞬态属性,然后计算它们在相关类中需要。

  2. 但是,如果您指定一个类并为任何瞬时属性定义任意的getter方法而不在对象模型中声明,那么事情就会起作用(只要实体在模型中链接到该类)

我的问题:在对象模型中声明瞬态属性有什么好处?
我只看到一个down-side:每次添加一个transient属性(例如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.

我缺少什么?

推荐答案

核心数据编程指南


-supported属性是一个对象,那么在托管对象模型中,您将其类型指定为未定义,并且它是短暂的。实现实体的自定义类时,不需要添加属性的实例变量,您可以使用托管对象的私有内部存储。关于下面描述的实现的一点要点是它们缓存瞬态值。这使得访问价值更有效 - 变更管理也是必要的。如果你定义了自定义的实例变量,那么你应该在doTurnIntoFault中清理这些变量,而不是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.

然而,它并没有阐明其对瞬态属性的立场。其实第二个要点就是阐述这一段几乎听起来像是一个矛盾。一个快速测试(带有name属性的简单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天全站免登陆