Skip to content

Instantly share code, notes, and snippets.

@nashysolutions
Last active November 14, 2020 05:00
Show Gist options
  • Save nashysolutions/1feb33edb99da113d958342947b701d0 to your computer and use it in GitHub Desktop.
Save nashysolutions/1feb33edb99da113d958342947b701d0 to your computer and use it in GitHub Desktop.
extension MenuViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
table.reloadItem(at: indexPath, save: { (item) in
switch selections.contains(item) {
case true: selections.remove(item)
case false: selections.insert(item)
}
}, animate: false)
}
}
// in table handler
func reloadItem(at indexPath: IndexPath, save: (MenuItem) -> Void, animate: Bool = true) {
let item = dataSource.itemIdentifier(for: indexPath)!
var snapshot = dataSource.snapshot()
save(item)
snapshot.reloadItems([item])
dataSource.apply(snapshot)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment