0

Currently, I've been following a Coursera course called Intro to Swift Programming 5. The video I was following was about the Xcode's MVC, and I'm getting the following error, even though I did what the person on screen had done:

Thread 1: Exception: "[< UIViewController 0x7fd2b6c053d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key colorLabel."

I've tried looking it up, but I don't see where I would have referenced something and deleted it. I've also checked to see if there are any warning signs near any of my reference outlets on the Main Storyboard, but everything seems to be in order there as well.

My code is as follows:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var modelLabel: UILabel!

    @IBOutlet weak var colorLabel: UILabel!

    @IBOutlet weak var priceLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        let appleProduct = AppleProduct(name: "iPhone X", color: "Space Gray", price: 999.99)
        modelLabel.text = appleProduct.name
        colorLabel.text = "in \(appleProduct.color)"
        priceLabel.text = "$\(appleProduct.price)"
    }
}

Has anyone else experienced this issue and can help me? I'd greatly appreciate it, and I'm happy to provide any other code that's needed if this is unclear. Thanks!

shim
  • 9,289
  • 12
  • 69
  • 108
Lilac Rose
  • 23
  • 3
  • 1
    You didn't set correctly the class in your Storyboard of `ViewController`. It's currently a `UIViewController` instead. – Larme May 18 '20 at 21:03
  • May I ask what it's supposed to be instead? If I try changing UIViewController to ViewController, it gives me many more errors saying that it's inheriting from itself. – Lilac Rose May 18 '20 at 21:13
  • 1
    Not in the code you posted, in InterfaceBuilder, in the storyboard: https://stackoverflow.com/questions/33033129/xcode-7-1-swift-2-unknown-class-in-interface-builder-file/36975344 – Larme May 18 '20 at 21:14
  • My current Storyboard class is "Custom Pretty View", which corresponds to my View File, CustomPrettyView.swift. Is this not what it should be? – Lilac Rose May 18 '20 at 21:32

1 Answers1

0

CustomPrettyView is the class of the view. But you also need to declare the class of the view controller itself; otherwise Xcode will decide that it's UIViewController.

Click on the scene and in the inspector in the "Custom Class" section it will say that the class is UIViewController and it will be faded because you haven't overridden it. Change that to be the name of your view controller, which is ViewController.

I would also recommend that you change that class name to be something more meaningful, maybe PrettyViewController or something like that.

Rudedog
  • 4,323
  • 1
  • 23
  • 34