Skip to content

Instantly share code, notes, and snippets.

@AndreyPanov
Created May 23, 2016 12:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreyPanov/45939e5f2a2304eb85be4a335f993617 to your computer and use it in GitHub Desktop.
Save AndreyPanov/45939e5f2a2304eb85be4a335f993617 to your computer and use it in GitHub Desktop.
extension UITableView {
func animatedInsert(indexPaths paths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation = .Automatic) {
guard paths.isEmpty == false else { return }
beginUpdates()
insertRowsAtIndexPaths(paths, withRowAnimation: animation)
endUpdates()
}
func animatedlReload(indexPaths paths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation = .Automatic) {
guard paths.isEmpty == false else { return }
beginUpdates()
reloadRowsAtIndexPaths(paths, withRowAnimation: animation)
endUpdates()
}
func animatedMove(indexPaths fromPaths: [NSIndexPath], toIndexPaths toPaths: [NSIndexPath]) {
guard fromPaths.count > 0 else { return }
guard fromPaths.count == toPaths.count else {
assert(false, "Passing different amount of start and end index path possitions")
return
}
beginUpdates()
for (index, path) in fromPaths.enumerate() {
moveRowAtIndexPath(path, toIndexPath: toPaths[index])
}
endUpdates()
}
func animatedDelete(indexPaths paths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation = .Automatic) {
guard paths.isEmpty == false else { return }
beginUpdates()
deleteRowsAtIndexPaths(paths, withRowAnimation: animation)
endUpdates()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment