How to handle CRUD operation with Diffable Data Source & NSFetchedResultsController

173 Views Asked by At

I have a simple product store screen of 4 rows with each row containing 4-5 products.

Currently I have the following setup

  • Controller calls the backend server and gets the data
  • Save the models to Core Data
  • This triggers an update of NSFetchedResultsController
  • Apply the new snapshot using Diffable Data Source

This setup works great when new products are added to any row or are updated in some way.

But I am unable to find a way on how to handle the scenario when a product is removed in the API response ? because whenever I receive a response I save it in Core Data base and then rely on the FRC trigger to apply the snapshot.

So If an existing product is removed in the response the product still continues to show in the store as it also needs to be removed in the DB as well. So before saving into DB I always have to delete all the existing data and then save the new data for changes to take effect.

Can anybody suggest a change in my setup to handle this scenario or any particular flow to handle it ?

0

There are 0 best solutions below