Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check the state of a checkbox for macOS applications using Swift

The task seemed relatively simple, I wanted an if statement to determine if a check box is checked or not apparently check boxes but am at a loss

I've tried

if checkbox.state == everythign i can think of but it always errors either EXC_BAD_INSTRUCTION or using wrong cant convert variable type to other variable type

like image 401
Jason M Avatar asked Jan 09 '15 23:01

Jason M


2 Answers

i did this on my project and it worked well

if sender.state == .on{
            casa_ospiti_text.stringValue = "CASA"
        }
        else{
            casa_ospiti_text.stringValue = "OSPITI"
        }

where it changes the value of a textfield (casa_ospiti_text) with constants strings.

like image 113
Giacomo Sighinolfi Avatar answered Sep 23 '22 12:09

Giacomo Sighinolfi


Xcode 9 • Swift 4

You can switch the checkbox state property to check if it is on or off as follow:

switch sender.state {
case .on:
    print("on")
case .off:
    print("off")
case .mixed:
    print("mixed")
default: break
}
like image 31
Leo Dabus Avatar answered Sep 24 '22 12:09

Leo Dabus