问题描述
我有一个实体物件国家/地区具有国家/地区名称和国家/地区代码。它是NSManagedObject的子类,我使用它与核心数据模型来存储它的值到持久存储。
I have an entity object Country with country name and country code. It is a subclass of NSManagedObject and I am using it with core data model to store its value to a persistent store.
我有一个地方,相同的国家对象将使用作为正常对象,即我将使用它来存储一些临时国名。
I have a place where the same Country object will used as a normal object i.e. I will use it to store some temporary country name.
为此,我已将国家/地区初始化为以下
For that I have initialized the Country as following
[NSManagedObject alloc] init]
$ b $ p
初始化成功完成,但是我不能为该对象设置任何属性。
因此我做了一个探索。在那里我发现,NSManagedObject的init不支持按照文档。
Initialization successfully done, but I am not able to set any property to that object.Hence I did an exploration. In that I found that, init for the NSManagedObject is not supported as per the documentation.
我不知道如何使用NSManagedObject国家与CoreData以及一个普通的对象。
I dont know how to use the NSManagedObject Country with CoreData as well as a normal Object.
如果有可能,请让我知道解决方案,因为我迫切需要这个asap ..
If there is a possibility, please let me know the solution as I am in desperate need of this asap..
提前感谢。
推荐答案
NSManagedObject类文档概述的第2段:
2nd paragraph of the NSManagedObject class documentation's overview:
从方法的文档:
文档实际上很好。
您不想尝试在可行的CoreData堆栈之外使用NSManagedObject。 NSManagedObject被明确设计为在正确配置的Core Data环境中工作。如果您需要一个临时实例,您可以创建一个内存存储或在您的常规存储中创建一个,只是不保存更改,而不先删除它。
You do not want to try to use an NSManagedObject outside of a viable CoreData stack. NSManagedObjects are quite explicitly designed to work within a correctly configured Core Data environment. If you need a temporary instance, you can either create an in-memory store or create one in your regular store and just don't save the changes without deleting it first.
这篇关于NSManagedObject子类作为管理对象外部的正常对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!