Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
  2. tableView.beginUpdates()
  3. }
  4.  
  5. func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
  6. switch type {
  7. case .insert:
  8. tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade)
  9. case .delete:
  10. tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade)
  11. case .move:
  12. break
  13. case .update:
  14. break
  15. }
  16. }
  17.  
  18. func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
  19. switch type {
  20. case .insert:
  21. tableView.insertRows(at: [newIndexPath!], with: .fade)
  22. case .delete:
  23. tableView.deleteRows(at: [indexPath!], with: .fade)
  24. case .update:
  25. tableView.reloadRows(at: [indexPath!], with: .fade)
  26. case .move:
  27. tableView.moveRow(at: indexPath!, to: newIndexPath!)
  28. }
  29. }
  30.  
  31. func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
  32. tableView.endUpdates()
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement