Error: Failed to connect outlet from ... to (NSTextField): missing setter or instance variable

6.7k views Asked by At

Why does this code:

if Note1Math.stringValue == "" {         
        TxtFilled = 0

        }else{

        TxtFilled = 1

    }

give this error?:

2015-06-18 20:20:17.633 Office[41763:430750] Failed to connect (Note1) outlet from (Office.ViewController) to (NSTextField): missing setter or instance variable.
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

2

There are 2 answers

0
Ken Thomases On BEST ANSWER

This part of the message:

2015-06-18 20:20:17.633 Office[41763:430750] Failed to connect (Note1) outlet from (Office.ViewController) to (NSTextField): missing setter or instance variable.

does not come from that code. It comes from the loading of a NIB or storyboard. Presumably, you had named an outlet Note1 at one time, connected it in the NIB or storyboard, and then renamed it to Note1Math in the code without fixing the NIB/storyboard.

Then, later, when you accessed Note1Math, it was nil (because it was not connected in the NIB/storyboard). That caused the second message:

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

The solution is to go into the NIB or storyboard, disconnect the outlet with the old name, and reconnect the outlet.

1
nachshon f On

Try this...

if the Note1Math is a textbox...

if Note1Math.text == "" {

        TxtFilled = 0

        }
else{

        TxtFilled = 1


    }

If the Note1Math is just a string...

  if Note1Math == "" {

            TxtFilled = 0

            }
    else{

            TxtFilled = 1


        }