1

I have the following code:

func textSwitch(t: UILabel) {
    if(t.hidden == true) {
        t.hidden = false
    }
    else{
        t.hidden = true
    }
}

@IBOutlet weak var recordingtext: UILabel!
@IBAction func recordButton(sender: UIButton) {
    textSwitch(recordingtext)
}

Running it results in the NSUknownKeyException. I am very new to iOS and Swift. Can anyone help me understand not just how to fix this, but why the code will not run? From looking at other questions it looks as if this exception is normally thrown when the object being referenced doesn't exist, but I do not believe that is the case here? I really don't know enough to be certain at this point.

mstagg
  • 507
  • 4
  • 16
  • Insert a `print (recordingtext)` right above the call to `textswitch` and see what it contains. – qwerty_so Jan 08 '15 at 19:50
  • Did you correctly assign the `IBOutlet` for `recordingtext`? – Ian MacDonald Jan 08 '15 at 19:53
  • The program doesn't get far enough to actually print anything. Here is the error message: _2015-01-08 13:53:32.455 Pitch Perfect[2828:73688] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key recordingButton.'_ – mstagg Jan 08 '15 at 19:56
  • You have a discrepancy. You're specifying "recordButton" in your code, but the key you're using "recordingButton" – lewiguez Jan 08 '15 at 20:00
  • I fixed the discrepancy and it still throws the exception – mstagg Jan 08 '15 at 20:06
  • Your xib / storyboard is broken – mustafa Jan 08 '15 at 20:14
  • possible duplicate of [What does this mean? "'NSUnknownKeyException', reason: ... This class is not key value coding-compliant for the key X"](http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key) – jtbandes Aug 03 '15 at 06:17

1 Answers1

1

The destination controller is probably not defined.