Skip to content

Instantly share code, notes, and snippets.

@groue
Created March 29, 2016 21:06
Show Gist options
  • Save groue/e684e14c38853be7b228143822daa00d to your computer and use it in GitHub Desktop.
Save groue/e684e14c38853be7b228143822daa00d to your computer and use it in GitHub Desktop.
// MARK: - FetchedRecordsControllerDelegate
extension PersonsViewController : FetchedRecordsControllerDelegate {
func controllerWillChangeRecords<T>(controller: FetchedRecordsController<T>) {
tableView.beginUpdates()
}
func controller<T>(controller: FetchedRecordsController<T>, didChangeRecord record: T, withEvent event:FetchedRecordsEvent) {
switch event {
case .Insertion(let indexPath):
tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
case .Deletion(let indexPath):
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
case .Update(let indexPath, _):
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
configureCell(cell, atIndexPath: indexPath)
}
case .Move(let indexPath, let newIndexPath, _):
// Actually move cells around for more demo effect :-)
let cell = tableView.cellForRowAtIndexPath(indexPath)
tableView.moveRowAtIndexPath(indexPath, toIndexPath: newIndexPath)
if let cell = cell {
configureCell(cell, atIndexPath: newIndexPath)
}
}
}
func controllerDidChangeRecords<T>(controller: FetchedRecordsController<T>) {
tableView.endUpdates()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment