Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
- tableView.beginUpdates()
- }
- func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
- switch type {
- case .insert:
- tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade)
- case .delete:
- tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade)
- case .move:
- break
- case .update:
- break
- }
- }
- func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
- switch type {
- case .insert:
- tableView.insertRows(at: [newIndexPath!], with: .fade)
- case .delete:
- tableView.deleteRows(at: [indexPath!], with: .fade)
- case .update:
- tableView.reloadRows(at: [indexPath!], with: .fade)
- case .move:
- tableView.moveRow(at: indexPath!, to: newIndexPath!)
- }
- }
- func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
- tableView.endUpdates()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement