Reputation: 397
Core data application, that Syncs user data from CloudKit
.
We have two core data context
Problems:
Since its a parent-child setup the changes from parent do not get reflected in child. So while the child is syncing changes to CloudKit
if the parent context get updated, then child is not aware of that changes.
Say child context is trying to upload a record A to CloudKit
meanwhile if user modifies the same record as below
User updates :- the new updates are lost when child saves the record to parent.
User Deletes :- (we just mark it as deleted) the child re-saves the child since it do not get the property marked as deleted.
Question:
Can child somehow know of the parent updates? Can i refresh the object before i save?
In Parent-Child Setup does child always overrides parent changes without getting merge conflicts?
Upvotes: 3
Views: 619
Reputation: 30811
FYI Parent/Child contexts are not for this they are for create/update screens, where changes made by the user can be cancelled and discarded leaving the main context alone. For network sync you should be using a background context associated with the persistent store. See NSPersistentContainer
newBackgroundContext
.
Upvotes: 2
Reputation: 427
Have a look at this tutorial it may help.
Multiple Context swift tutorial
Upvotes: -1