0

Sorry I do not have specific question but I cannot figure out how to get around this error. The app itself does not show any errors in Xcode but it crashes at start with the error message this class is not key value coding-compliant for the key guessMade.

@IBOutlet weak var numberGuessed: UITextField!
@IBOutlet weak var answer: UILabel!

@IBAction func guessMade(sender: AnyObject) {

    var numberOfFingers  = arc4random_uniform(11)
    var numberString = String(numberOfFingers)
    var integerGuessed = numberGuessed.text

    if numberString == integerGuessed {
        self.answer.text = "You're right! I had \(integerGuessed) fingers up"
    }else {
        self.answer.text = "Nope! I had \(numberString) fingers up"

    }
}

It is a very small project so this is the entire code. The button guessMade is supposed to check to see if the number entered in the text field matches the randomly generated number also produced when the button is pressed. Any ideas what the error is telling me wrong?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
punygod
  • 197
  • 2
  • 17
  • 1
    Delete all IBOutlet and re-link them again. Have a try. – Zigii Wong Jan 07 '15 at 02:23
  • 1
    Please [search on the error](http://stackoverflow.com/search?q=this+class+is+not+key+value+coding-compliant+for+the+key). This issue has been covered many times. – rmaddy Jan 07 '15 at 02:25
  • @WorldOfWarcraft thank you I somehow had that button linked twice. – punygod Jan 07 '15 at 02:30
  • self.answer.text = arc4random_uniform(11).description == numberGuessed.text ? "You're right! I had \(integerGuessed) fingers up" : "Nope! I had \(numberString) fingers up" – Leo Dabus Jan 07 '15 at 03:50
  • You can change all those lines of code for a single one. BTW Why do you declare it all as vars if they are constants? – Leo Dabus Jan 07 '15 at 03:53
  • @LeonardoSavioDabus because the app needs to generate a random number every time the button is pressed and match it with whatever is entered into the text field. – punygod Jan 08 '15 at 19:10
  • It doesn't make any difference. – Leo Dabus Jan 09 '15 at 00:48
  • 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:24

1 Answers1

4

Inspect your view controllers files owner, such as:

enter image description here

See if there is anything yellow waring marked like this, if there is anything delete this. Hope this helps.. :)

Community
  • 1
  • 1
Rashad
  • 11,057
  • 4
  • 45
  • 73