Jordan H
Jordan H

Reputation: 55725

How to be notified when received changes from only the remote CloudKit database?

I'm building an app with Core Data and CloudKit. I need to detect when remote changes have been pushed to the app and are available in the local database to perform some work on the new data set. I've implemented .NSPersistentStoreRemoteChange like so:

NotificationCenter.default.addObserver(self, selector: #selector(self.storeRemoteChange(_:)), name: .NSPersistentStoreRemoteChange, object: container.persistentStoreCoordinator)

The problem is this notification is received even when changes haven't been received from the remote CloudKit database, such as 4 times when the app is launched, and when a modification is made to the local database. How can I know only when changes have been received from the remote database?

Upvotes: 7

Views: 1133

Answers (2)

Jordan H
Jordan H

Reputation: 55725

While I wasn't able to detect only this scenario, I did accomplish my needs by utilizing NSManagedObjectContextObjectsDidChangeNotification and performing both remote and local change processing when this notification is triggered.

Upvotes: 1

Related Questions