I am currently making an app that needs it's CoreData storage to be synced via iCloud across devices.
Everything works fine except that it's not synching in real-time. (Or at least somewhat close to that). It's not syncing at all when I am doing nothing on Device2 after Device1 changed something. In fact, I have to minimize and reopen the app on Device2 to get the synching working.
This demonstrates it very well: (source)

Here would be a snippet of my code:
let container: NSPersistentCloudKitContainer
var context: NSManagedObjectContext { container.viewContext }
init() {
container = NSPersistentCloudKitContainer(name: "__Decision")
guard let description = container.persistentStoreDescriptions.first else { ... }
description.setOption(true as NSObject, forKey:
NSPersistentStoreRemoteChangeNotificationPostOptionKey)
container.loadPersistentStores(completionHandler: { ... })
container.viewContext.automaticallyMergesChangesFromParent = true
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
NotificationCenter.default.addObserver(self, selector: #selector(self.processUpdate), name: .NSPersistentStoreRemoteChange, object: nil)
}
@objc func processUpdate(notification: NSNotification) {
operationQueue.addOperation {
DispatchQueue.main.async { ... } //Fetch new synched data and update UI
}
}
lazy var operationQueue: OperationQueue = {
var queue = OperationQueue()
queue.maxConcurrentOperationCount = 1
return queue
}()
I have followed the documentation by apple and other tutorials, since this is my first project with CloudKit + CoreData.
Everything seems identical to what they have done.. I have no idea and been working on this problem since days.
Thank you!