Skip to content

Commit

Permalink
Update ListSelectorViewController to use safe index accessors (#14077)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ecarrion authored Sep 30, 2024
2 parents 5161e39 + b25ba6a commit bc4301b
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ UIViewController, UITableViewDataSource, UITableViewDelegate where Command.Model

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(Cell.self, for: indexPath)
let model = command.data[indexPath.row]
// Configures the cell's `accessoryType` before calling `command.configureCell` so that the command could override the `accessoryType`.
cell.accessoryType = command.isSelected(model: model) ? .checkmark: .none
command.configureCell(cell: cell, model: model)

if let model = command.data[safe: indexPath.row] {
// Configures the cell's `accessoryType` before calling `command.configureCell` so that the command could override the `accessoryType`.
cell.accessoryType = command.isSelected(model: model) ? .checkmark: .none
command.configureCell(cell: cell, model: model)
}
return cell
}

Expand All @@ -102,8 +103,7 @@ UIViewController, UITableViewDataSource, UITableViewDelegate where Command.Model
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

let selected = command.data[indexPath.row]
if !command.isSelected(model: selected) {
if let selected = command.data[safe: indexPath.row], !command.isSelected(model: selected) {
command.handleSelectedChange(selected: selected, viewController: self)
tableView.reloadData()
}
Expand Down

0 comments on commit bc4301b

Please sign in to comment.