Reputation: 6372
How can I copy an NSManagedObject
from one NSManagedObjectContext
to another?
I have 2 different NSManagedObjectContext
, each with it's own NSManagedObjectModel
and separate persistent store. Each of the 2 MOC has an entity called Observation
that is tied to the same Observation class.
I want to copy objects from one MOC to the other. Since the objects are of the same class, I would like to just fetch an object from one MOC and save it to the other. Is this possible, or do I need to insert a new object into the target MOC and then set each property one at a time?
Upvotes: 3
Views: 964
Reputation: 80265
You need to copy one object and insert a new one into the other managed object context. Most likely you would have to copy the property values over one by one to do this.
The reason is that all these objects have opaque unique ID, so you cannot just take it from one context to the other.
Upvotes: 2