-3

I'm a complete noob at programming it's my first try. I started with the Udemy course from Rob Percival. I'm now at my first app. What it should do:

I enter the age from the dog and when I click "Find Age" it should show me the "real age" from the dog (entered age * 7 )

So ok everything works fine till I get to the point where I want that the final age will show in the app. But I always get the error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Dog_Years.ViewController 0x7fa05b5baa80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dogYears.'

I don't get why. I googled a bit but can't find a solution.

Here is the code:

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var dogRealYears: UILabel!
    @IBOutlet weak var age: UILabel!    
    @IBOutlet weak var textField: UITextField!

    @IBAction func findAge(sender: AnyObject) {            
        var enteredAge = textField.text.toInt()    
        var dogYears = enteredAge! * 7
        dogRealYears.text = "Your dog is \(dogYears)"
    }
}
Stefan Arentz
  • 34,311
  • 8
  • 67
  • 88
Dominik Huber
  • 105
  • 10
  • 1
    When you were first setting up your app in Interface Builder, was the text field in your view controller called “dogYears” instead of “dogRealYears”? That error looks like what happens when IB is trying to connect a bit of your UI to an outlet that doesn’t exist anymore. – Noah Witherspoon Jul 17 '15 at 17:07
  • Yes that could possible be the case! What can I do to solve this? :) – Dominik Huber Jul 17 '15 at 17:09
  • possible duplicate of [This class is not key value coding-compliant for the key](http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant-for-the-key) – jtbandes Aug 01 '15 at 21:52

1 Answers1

0

It sounds like a xib problem. Check your connections and make sure you don't have a field wired up to a non existent property

MongoTheGeek
  • 294
  • 1
  • 10
  • Sorry but what is XIB? Yes I changed the fields a bit. How can I solve this problem? Start from scratch? – Dominik Huber Jul 17 '15 at 17:10
  • xib is a different file type for UI design...you're probably using a storyboard instead. If so, go into your storyboard, look at the connections inside your ViewController scene (use Connections Inspector), and fix the one that points to `dogYears`. – Phillip Mills Jul 17 '15 at 17:13
  • Hey thx for the tipp. I found it at "View" --> Utilities --> Show Connections Inspector. But when I click it nothing happens in xCode. Am I doing it very wrong? – Dominik Huber Jul 17 '15 at 17:19
  • Hey, I could solve it thanks to you. I deleted all the connections and made new one. Now it is working! Thank you very much! – Dominik Huber Jul 17 '15 at 17:43