Basic data with iCloud: how to sync NSManagedObjects only after another NSManagedObjects type has already been synced
Good morning,
I have a problem with my Swift 1.2 app that uses Core Data from iCloud.
I have 2 custom NSManagedObjects classes: object 1 represents Notes and object 2 represents projects. A Note object has the property of only one Project, but a Project can "contain" many Notes.
I have a problem syncing between different devices via iCloud: when I create a new project on device 1 and then immediately create multiple Note objects that have this new project as a property, if I am "lucky" after syncing on device 2 I have exact data ... same new project containing the same notes.
Often I have had no luck with the sync order: iCloud syncs some new Notes first, but not the Project object, which is a property of the Note objects. In this case, the imported Notes are "orphans" that do not have an assigned project (I checked, the project property is zero in this case) and therefore are displayed in an unnamed section of the tableView .
When this happens, I go broke a little: the notes on device 1 are assigned to their Project, but on device 2 they are not and never will be. I wrote a method called after context merge in persistentStoreDidImportUbiquitousContentChanges
that can change the project property for orphan notes from nil to another Project, but since my new project is not actually in sync on that device, I can't move them there, only in another project object ...
I don't understand: It seems to me that what I am trying to do should be a very simple use of Core Data with iCloud sync: two objects with a one-to-one relationship created on the same device that should maintain the same exact relationship after syncing on the device 2. Instead, when I am out of luck (I keep using this word because it seems to me that nothing on my part affects the order of synchronization and does not justify the reasons why some projects never synchronize) one of the objects is not synchronized on device 2.
My question is, is there a way to first sync all instances of a particular NSManagedObject (in my case, Projects), and only after that sync successfully syncs other NSManagedObjects (Notes) types?
source to share
No one has answered this question yet
See similar questions:
or similar: