Almost 2 years ago, I asked here (Core data and iCloud sync not working in live App) about a problem I had syncing core data on iCloud. The problem was resolved deploying the schema to production.
No problems so far, but some months ago I noticed my App some times was syncing, sometimes do not.
Nowadays, the problem is, not syncing at all, on the simulator works OK, I open 2 devices and they sync without problems.
Going live (downloading the App from the AppStore), using 2 iPhones, same iCloud account, does not sync 99% of the time.
For instance:
Any ideas?
AppDelegate.swift
lazy var persistentContainer: NSPersistentCloudKitContainer = {
let container = NSPersistentCloudKitContainer(name: "whatever")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
return container
}()
func saveContext () {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
Found the problem...
I inadvertently created a second configuration in the datamodel, deleting it solved the problem, iCloud is syncing again without any problem.