arraysuitableviewcheckmark

How to get the value of Int in [Int : Bool]?


Im Trying to get the value of Int from [Int : Bool] so that i can remove the row value from the tableView.

Here's my code.

 var checkmarks = [Int : Bool]()

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    selectedNamesIndex = indexPath.row
    let cell = tableView.cellForRow(at: indexPath)

    if let index = selectedNamesIndex {
        if (cell?.accessoryType == .checkmark) {
            cell!.accessoryType = .none
            checkmarks[indexPath.row] = false
            hasChecked = false

            let indexPathTapped = tableView.indexPath(for: cell!)
            let name = namelist[(indexPathTapped!.row)]
            print(name, hasChecked)
            selectedNamesToBroadcast.remove(at: checkmarks) // theres an error here: Cannot convert value of type '[Int : Bool]' to expected argument type 'Int'
        } else {
            cell!.accessoryType = .checkmark
            checkmarks[indexPath.row] = true
            hasChecked = true

            let indexPathTapped = tableView.indexPath(for: cell!)
            let name = namelist[(indexPathTapped!.row)]
            print(name, hasChecked)
            selectedNamesToBroadcast.append(name)

            let selectedNamesToBroadcast = name

        }
    }

I want to be able to uncheck the color. So that when I update the database, it will be removed.


Solution

  • You probably want

    if let index = selectedNamesToBroadcast.index(of: name) {
        selectedNamesToBroadcast.remove(at: index)
    }