paulw11 / Seam3

Cloudkit based persistent store for Core Data
Other
208 stars 25 forks source link

Using with NSFetchedResultsController #93

Open grahamburgsma opened 5 years ago

grahamburgsma commented 5 years ago

I am trying to use Seam3 with an NSFetchedResultsController which uses the main viewContext (persistentContainer.viewContext). Unfortunately, any changes made by Seam3 from a sync aren't notifying the FRC delegate. I believe this is because the changes from the localStoreMOC aren't merged to the main viewContext as they should.

I tried finding the bug myself but I just started using CoreData a few weeks ago and am no expert, nothing I've tried has worked. If anyone could assist that would be great.

I understand I could use the SMStoreDidFinishSyncOperationNotification to update my UI instead of using NSFetchedResultsController, but using FRC is definitely the more efficient and preferred approach so I think this is a bug.

Would be happy to fix it myself if anyone can point me in the right direction. Thank you!

grahamburgsma commented 5 years ago

Just discovered the original Seam project (https://github.com/nofelmahmood/Seam) handles this in the didFinishSyncing notification, seems like a good approach.

NSNotificationCenter.defaultCenter().addObserver(self, selector: "didFinishSyncing:",
                                                name: SMStoreDidFinishSyncingNotification,
                                                object: seamStore)

func didFinishSyncing(notification: NSNotification) {
  // Merge Changes into your context after syncing completes
  mainContext.mergeChangesFromStoreDidFinishSyncingNotification(notification)
}