Registering to receive notifications of remote CloudKit changes not working
You observed the persistent container instead of the store coordinator, it should be this:
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(persistentStoreRemoteChangeNotification:) name:NSPersistentStoreRemoteChangeNotification object:_persistentContainer.persistentStoreCoordinator];
Wherever you access your app’s persistent CloudKit container to grab the viewContext
, you need to set the automaticallyMergesChangesFromParent
property to true
.
lazy var managedContext: NSManagedObjectContext = {
self.storeContainer.viewContext.automaticallyMergesChangesFromParent = true
return self.storeContainer.viewContext
}()
Making this one-line change will enable the app (which is supported by NSFetchedResultsController
) to update the UI in response to remote data changes…