[Solved] selected and deselected checkbox in Swift


try this below code

if let button = sender as? UIButton {
        if button.isSelected {
            // set selected
            button.isSelected = true
        } else {
            // set deselected
            button.isSelected = false
        }
    }

For shorthand, try this

if let button = sender as? UIButton {
     button.isSelected = !button.isSelected
}

1

solved selected and deselected checkbox in Swift