问题描述
有时我需要实例化CoreDateEntity来存储一些信息以便临时使用。
但是我不需要将它存储到DB中。
Sometimes I need instantiate CoreDateEntity to store some infomations for temporarily using.But I needn't it be stored into DB.
目前我创建了一个类似的类,它具有与CoreDateEntity相同的结构。
它运行良好,但我必须在两个模型之间做很多数据传输。
currently I created a similar class which have same structures as the CoreDateEntity does.It works well but I have to do many datas transfer between Two models.
有更好的方法来处理吗?
Is there any better way to handle this?
感谢所有回复。但你们只是给我一半答案。考虑一下,我需要把一些没有MOC的实体放到当前数据库池中,我该怎么做呢?我已经检查了CoreData的文档,似乎我没有找到API将一个实体从MOC转移到另一个MOC(管理对象上下文)。
Thanks for all the replies. but you guys just give me half answer of this. consider about this, I need place some entity without MOC into current database pool, how could I do this? I already checked the documents of CoreData, seems I didn't find API to transfer one entity from MOC to another MOC(manage object context).
推荐答案
根据Apple文档,如果您指定nil为上下文,则可以初始化一个无上下文的托管对象。
According to Apple docs you can initialize a managed object without context if you specify nil as context.
- (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext:(NSManagedObjectContext *)context
这篇关于创建核心日期实体实例但不希望它被存储(非持久性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!