Create an instance of the kernel entity, but do not want it to be saved (mutable)

Sometimes I need to create an instance of CoreDateEntity to store some data for temporary use. But I do not need to store it in the database.

I have currently created a similar class that has the same structures as CoreDateEntity. It works well, but I need to do a lot of data transfer between the two models.

Is there a better way to handle this?


Thanks for all the answers. but you guys just give me half the answer. think about it, I need to place some object without MOC in the current database pool, how can I do this? I already checked the CoreData docs, it seems that I did not find an API for transferring one object from MOC to another MOC (object context management).

+1
source share
3 answers

According to Apple docs, you can initialize a managed object without a context by specifying nil as the context.

- (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext:(NSManagedObjectContext *)context 
+6
source

When setting up the data model, you can assign objects to different stores. Do store in persistent storage and the other in memory. You cannot form relationships between stores, but it looks like you don't need it.

To assign a configuration, click on the configuration tab (the one indicated in the wrench icon) in the details of the object (where you specify its name, class and parent). When you create persistent storage, add the configuration name to the parameter dictionary.


Update:

I think you maybe too much. It looks like you have some managed objects that will be temporary, and some of them will be saved, but sometimes you might want to save temporary objects. I do not think you should try to separate the β€œtemporary” objects. It just adds complexity without any performance benefits. Instead, just use regular persistent objects, and then delete the ones you don't need.

First try the simplest solution.

+2
source

Use two different contexts of the managed entity and save the objects from only one context. Be careful not to establish relationships between objects of two different contexts - this does not work.

0
source

All Articles