Last active
June 26, 2017 23:40
-
-
Save sebastienwindal/b391f1c1aec15f45534f009d05550f89 to your computer and use it in GitHub Desktop.
NSFetchedResultsController swift 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment