NSControl.StateValue

Hi, I´m starting to code those days and now got stuck and can´t help myself out, so I´d be happy if someone could help me.

The code is this:

        if let context = (NSApplication.shared.delegate as? AppDelegate)?.persistentContainer.viewContext {

            let toDoItem = ToDoItem(context: context)

            toDoItem.name = textField.stringValue
            if importantCheckBox.state == 0 {
                // Not important
                toDoItem.important = false
        } else {
                // Important
                toDoItem.important = true
            }

            (NSApplication.shared.delegate as? AppDelegate)?.saveAction(nil)

It shows me following

Binary operator '==' cannot be applied to operands of type 'NSControl.StateValue' and 'Int'

The Problem seems to be the " == "

May someone give me a hint to help me out?

Thank you in advance and best wishes!

Answered by robnotyou in 694914022

NSControl.StateValue is not an Int, it is used with a specific set of values:

  • on
  • off
  • mixed

Try:

if importantCheckBox.state == .off {
Accepted Answer

NSControl.StateValue is not an Int, it is used with a specific set of values:

  • on
  • off
  • mixed

Try:

if importantCheckBox.state == .off {
NSControl.StateValue
 
 
Q