Use Cocoa Bindings to conditionally enable a button if one or more checkbox are checked.
Take away is to use KVO Registering Dependent Keys.
- Use a dynamic variable with computed properties:
dynamic var atLeastOneSelectedCheckbox: Bool {
return [checkbox1, checkbox2, checkbox3].contains(where: { $0.state == NSOnState })
}
- Then make sure it gets computed everytime the state of a checkbox changes with:
dynamic class func keyPathsForValuesAffectingAtLeastOneSelectedCheckbox() -> Set<String> {
return ["checkbox1.cell.state",
"checkbox2.cell.state",
"checkbox3.cell.state"]
}
- And set the binding of the button to self. atLeastOneSelectedCheckbox