Reputation: 964
Imagine two managed object contexts, moc A and moc B filled with the same set of objects and sharing the same persistent store coordinator. Now, I delete an object from moc A and save the context. Will it still exist in moc B?
I tested that scenario and it seems like the objects still hang around in moc B, but I'm not sure if they are safe there, i.e. in a sense that I'll be able to write them back to the store.
The reason I'm asking is that I'd like to implement cut/copy/paste in a Core Data backed app but on copy I don't want to write the actual objects to the pasteboard and instead use the promise/data provider mechanism.
So let's say the user copies a bunch of managed objects and I write a promise to the pasteboard (an array of object IDs). Then, suppose the user deletes all these objects but later wants to paste them back somewhere. My data provider wouldn't be able to get them because they where deleted.
But I'm wondering what would happen if I had stored them in a private managed object context for safekeeping. Will they disappear from the safekeeping context after they're deleted from the main context?
Upvotes: 0
Views: 60
Reputation: 1224
the answer for question Will it still exist in moc B
is : It depends :)
So, if your code is running on iSO 10 (or above) the answer is Yes, it will still exist
because context A have deferent Generation
of data.
if your code is running on iOS 9 (or previous), the answer again is: It depends. If any object in context B is fault
, then if you will try to access any of properties (from this fault's object) your app will crash with sth like CoreData could not fulfill a fault
. Otherwise you can access those data (they are saved in raw cache). But (probably, I never try that) if you will try to save objects that was deleted by other context then I would expected an error from CoreData.
The answer for Will they disappear from the safekeeping context after they're deleted from the main context?
is:
No, they do not disappear but in iOS 9 (or previous) if you have some fault
s you will never can fulfill them (because the are no more exist anywhere).
Upvotes: 2