Created
March 29, 2016 21:06
-
-
Save groue/e684e14c38853be7b228143822daa00d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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