Skip to content

Instantly share code, notes, and snippets.

@nashysolutions
Last active November 12, 2020 19:29
Show Gist options
  • Save nashysolutions/ee76c9164fdca0c461e71a79f246511d to your computer and use it in GitHub Desktop.
Save nashysolutions/ee76c9164fdca0c461e71a79f246511d to your computer and use it in GitHub Desktop.
func toggleSelectedStateOfItem(at indexPath: IndexPath) {
let item = dataSource.itemIdentifier(for: indexPath)!
var snapshot = dataSource.snapshot()
item.isSelected = !item.isSelected
snapshot.reloadItems([item])
dataSource.apply(snapshot)
}
let cellProvider: CellProvider = { (tableView, indexPath, item) -> UITableViewCell? in
let cell = tableView.dequeueReusableCell(
withIdentifier: cellIdentifier,
for: indexPath) as! MenuItemTableViewCell
cell.accessoryType = item.isSelected ? .checkmark : .none
cell.textLabel?.text = item.name
return cell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment