I am trying to implement my existing coredata project using the UITableViewDiffableDataSource. My tableview is coupled using the NSFetchedResultsController and the corresponding delegate methods. I am able to list the data in the tableview using diffabledatasource. My datasource is declared with the generic types as below
UITableViewDiffableDataSource<String, NSManagedObjectID>
For enabling the editing mode in the tableview I subclassed the UITableViewDiffableDataSource. I can delete the cell from the tableview but not from my coreData. The code for deleting the cell is as below
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
if let identifierToDelete = itemIdentifier(for: indexPath){
var snapshot = self.snapshot()
snapshot.deleteItems([identifierToDelete])
apply(snapshot)
}
}
}
The below NSFetchedResultsControllerDelegate method is not called when I delete the cell.
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference)
I am not sure whether this is the correct way of coupling diffabledatasource with NSFetchedResultscontroller. Any help will be appreciated. Thanks in advance