Semantics of optional in the context of Transient Attributes in CoreData

淺唱寂寞╮ 提交于 2019-12-24 01:53:26

问题


What difference does it make if a transient attribute in core data is set to optional or non 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.


回答1:


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.

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



来源:https://stackoverflow.com/questions/43533078/semantics-of-optional-in-the-context-of-transient-attributes-in-coredata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!