CoreData中瞬时属性上下文中的可选语义 [英] Semantics of optional in the context of Transient Attributes in CoreData

查看:84
本文介绍了CoreData中瞬时属性上下文中的可选语义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果核心数据中的瞬态属性设置为可选或非可选,会有什么区别.

What difference does it make if a transient attribute in core data is set to optional or non optional.

通常,当您将实体设置为可选实体时,它允许将拥有该属性的实体存储为该属性设置为null.但是,在使用过渡属性的情况下,实际上并没有存储它们.那么将瞬态属性设置为optional会做什么吗?

Normally when you set an entity to being optional, it allows the entity owning that attribute to be stored with that attribute set to null. But in the case of transient attributes they aren't actually stored. So does setting a transient property to optional do anything?

如果使用可选的非瞬态属性计算瞬态属性,是否需要将其设置为可选属性?

Do you need to set a transient attribute to optional if it is calculated using an optional non-transient property?

任何见识都会受到赞赏.

Any insight is appreciated.

推荐答案

如果我未将瞬态属性设置为可选,则会出现以下错误: Core Data Save Error (NSValidationErrorKey, Cocoa error 1570)根据以下 SO Q/A 是您尝试存储具有非可选属性设置为Null的实体时遇到的错误.

If I don't set the transient attribute to optional I get the following error: Core Data Save Error (NSValidationErrorKey, Cocoa error 1570) which according to the following SO Q/A is an error you get when you try and store an entity with non-optional attributes set to Null.

如果将属性设置为可选,则不会发生此错误.因此,似乎您需要将瞬态属性设置为optional,以使核心数据知道您不需要/不想为瞬态属性存储值

If I set the attribute to optional this error does not occur. So it seems as though you need to set transient attributes to optional to let core data know that you don't need/want to store a value for the transient attribute

这篇关于CoreData中瞬时属性上下文中的可选语义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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