Last active
June 10, 2016 20:11
-
-
Save ateliercw/23f61d6f788b29b61b573e12e3f35bff to your computer and use it in GitHub Desktop.
Comparing a curried and un-curried deselect rows function
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
extension UIViewController { | |
func rz_smoothlyDeselectRows(tableView tableViewIn: UITableView?) { | |
guard let tableView = tableViewIn, | |
selectedIndexPaths = tableView.indexPathsForSelectedRows else { | |
return | |
} | |
let deselect = { (tableView: UITableView, animated: Bool) -> ((NSIndexPath) -> ()) in | |
return { indexPath in | |
tableView.deselectRowAtIndexPath(indexPath, animated: animated) | |
} | |
} | |
let reselect = { (tableView: UITableView, animated: Bool) -> ((NSIndexPath) -> ()) in | |
return { indexPath in | |
tableView.selectRowAtIndexPath(indexPath, animated: animated, scrollPosition: .None) | |
} | |
} | |
if let coordinator = transitionCoordinator() { | |
let animation = { (context: UIViewControllerTransitionCoordinatorContext) in | |
selectedIndexPaths.forEach(deselect(tableView, context.isAnimated())) | |
} | |
let completion = { (context: UIViewControllerTransitionCoordinatorContext) in | |
if context.isCancelled() { | |
selectedIndexPaths.forEach(reselect(tableView, false)) | |
} | |
} | |
let parentView = parentViewController?.view | |
coordinator.animateAlongsideTransitionInView(parentView, animation: animation, completion: completion) | |
} | |
else { | |
selectedIndexPaths.forEach(deselect(tableView, false)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment