Checking the state of a checkbox in OS

Hi all,
I'm used to checking the state of a toggle switch in ios with .isselected, but I'm struggling to find how to check the state of a checkbox in OS.
There is no 'isSelected' available. Is there an equivalent of that in OS? There is .state, but I cannot find a way to check if the state is on or off. There is NSOnState, but it says it is deprecated, with no info about what replaces it. My aim is to find out whether the user has elected to use a password or not.
Cheers for any help.

Accepted Reply

Please clarify what you are asking about. I assume you mean checkbox in macOS.


There is .state, but I cannot find a way to check if the state is on or off. There is NSOnState, but it says it is deprecated, with no info about what replaces it.


When I use NSOnState in My Xcode 10.1, it shows me a message with clear info about what replaces it:

'NSOnState' is unavailable in Swift: Use NSControl.StateValue.on


    @IBOutlet weak var checkBox: NSButton!

    // Somewhere in an action method...
        if checkBox.state == NSControl.StateValue.on {
            //...
        }


Or you can use the dot-leaded notation of Swift:

        if checkBox.state == .on {
            //...
        }

Replies

Please clarify what you are asking about. I assume you mean checkbox in macOS.


There is .state, but I cannot find a way to check if the state is on or off. There is NSOnState, but it says it is deprecated, with no info about what replaces it.


When I use NSOnState in My Xcode 10.1, it shows me a message with clear info about what replaces it:

'NSOnState' is unavailable in Swift: Use NSControl.StateValue.on


    @IBOutlet weak var checkBox: NSButton!

    // Somewhere in an action method...
        if checkBox.state == NSControl.StateValue.on {
            //...
        }


Or you can use the dot-leaded notation of Swift:

        if checkBox.state == .on {
            //...
        }

Awesome, thanks for that. Yes, I mean checkbox in mac os. I've clearly been looking in the wrong places. I didn't come across anything telling me what replaces it.