My current solution is to maintain a property that gets updated when the checkbox gets switched, and access that property instead of directly reading the checkbox’s state.
Something more elegant would be welcome: this is cumbersome; even more so if you want to make the property read-only or properly handle setting its value from inside the program.
class myViewController: NSViewController {
@IBOutlet private weak var myCheckbox: NSButtonCell!
public var myCheckboxState: Bool! // This can be read from any thread.
@IBAction func onMyCheckboxAction(_ sender: NSButtonCell) {
myCheckboxState = (myCheckbox.state == NSOnState)
}
override func viewDidLoad() {
super.viewDidLoad()
...
myCheckboxState = (myCheckbox.state == NSOnState)
...
}
...
}