I am implementing "duplicate" functionality in my iOS application. I'm using the following workflow:
- present a list of managed objects in initial context in root view controller
- when user taps on a row, create a new context pass it to "detail" view controller with duplicated managed object (
[[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 app开发者_开发技巧roach to this:
- Should I just reassign the pointer value and do not bother about MOC or...
- I should refetch the values in new context depending on their unique identifiers?
- Any other option I did not think of?
P.S. Contexts are using same persistent store coordinator.
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.
精彩评论