2 Replies
      Latest reply on Feb 9, 2019 5:12 PM by Liberty 456
      Liberty 456 Level 1 Level 1 (0 points)

        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.






        • Re: Checking the state of a checkbox in OS
          OOPer Level 7 Level 7 (4,875 points)

          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 {
                      //...
                  }