Nick, thanks for the input.
Behaviours I've noticed...
Scenario 1
Existing Core Data app with existing records.
Log in to the same Apple ID on different Simulators or Devices.
Enable NSPersistentCloudKitContainer and include container.viewContext.automaticallyMergesChangesFromParent = true
Only new records are synced to users CloudKit account and therefore across devices using the same Apple ID. Existing records remain only on the device on which they are created.
Scenario 2
Existing Core Data app with existing records.
Log in to the same Apple ID on different Simulators or Devices.
Enable NSPersistentCloudKitContainer and include container.viewContext.automaticallyMergesChangesFromParent = true
Enable NSPersistentHistoryTrackingKey...
guard let containerStoreDescription = container.persistentStoreDescriptions.first else {
fatalError("\(#function): Failed to retrieve a persistent store description.")
}
containerStoreDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
ANY records entered with NSPersistentHistoryTrackingKey = true are synced to users CloudKit account and therefore across devices that are using the same Apple ID.
Records entered prior to setting NSPersistentHistoryTrackingKey = true are never synced to users CloudKit account and remain only on the device on which they are created..
If NSPersistentCloudKitContainer is switched to NSPersistentContainer, run a few times, then switched back to NSPersistentCloudKitContainer, even the previous records entered with NSPersistentHistoryTrackingKey = true are synced to users CloudKit account... in fact, so long as the CloudKit development environment is not reset, the app can be deleted from all devices and again, previous records entered with NSPersistentHistoryTrackingKey = true are synced to users CloudKit account and therefore across devices. To reiterate, any records entered prior to setting NSPersistentHistoryTrackingKey = true are never synced to users CloudKit account and remain only on the device on which they are created.
Note that I have found it is necessary to set NSPersistentHistoryTrackingKey = true when switching from NSPersistentCloudKitContainer back to NSPersistentContainer (only done for testing purposes during my efforts to sync existing records).
Scenario 3
Existing Core Data app with no existing records.
Log in to the same Apple ID on different Simulators or Devices.
Enable NSPersistentCloudKitContainer and include container.viewContext.automaticallyMergesChangesFromParent = true
ALL records are synced to users CloudKit account and therefore across devices that are using the same Apple ID.
Unnecessary to separately enable NSPersistentHistoryTrackingKey.
Some developers have suggested some interesting (and functional) workarounds. The most interesting to me is to set a bool for each existing record following the successful load of an NSPersistentCloudKitContainer. Toggling this bool for each record after loading the NSPersistentCloudKitContainer forces a sync for those existing records. While it is the best workaround I have stumbled upon so far, this also seems extremely cumbersome to me and I cannot bring myself to write the code to make this work.
Surely there must be a mechanism to apply NSPersistentHistoryTrackingKey = true to all previous records? That is what I will be focussing on next, so any hints or guidance would be gratefully appreciated.