Reputation: 49354
I am implementing "duplicate" functionality in my iOS application. I'm using the following workflow:
[[DetailController alloc] initWithObject:clonedObject inContext:newContext]
).However I am struggling with the concept of reassigning relations from source object to the cloned one since their managed object contexts differ. What would be correct approach to this:
P.S. Contexts are using same persistent store coordinator.
Upvotes: 0
Views: 467
Reputation: 1171
Managed object IDs are thread safe. As such, you can pass a managed object ID to the MOC in your view controller, retrieve that object via existingObjectWithID:error, then perform the duplication in that context. This way, the objects never cross MOC boundaries.
Upvotes: 1