this class is not key value coding-compliant for the key setDefaultLabelText.'

Question

I know there are similar questions out there and I have looked at them but I can't seem to solve the problem. I'm actually working on this project here that Apple uses to help users learn Xcode: https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ConnectTheUIToCode.html#//apple_ref/doc/uid/TP40015214-CH22-SW1

This is my ViewController.swift code:

import UIKit

class ViewController: UIViewController {
    //MARK: Properties
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var mealNameLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a 
        nib.
    }


    //MARK: Actions
    @IBAction func setDefaultLabelText(_ sender: UIButton) {
        mealNameLabel.text = "Default Text"
    }
}

I keep getting this error even when I follow all of the steps:

2017-10-14 16:18:49.195098-0400 FoodTracker[1946:46609] [MC] Lazy loading 
NSBundle MobileCoreServices.framework
2017-10-14 16:18:49.195968-0400 FoodTracker[1946:46609] [MC] Loaded 
MobileCoreServices.framework
2017-10-14 16:18:49.211086-0400 FoodTracker[1946:46609] [MC] System group 
container for systemgroup.com.apple.configurationprofiles path is 
/Users/xcodeclub/Library/Developer/CoreSimulator/Devices/54569EE9-2F14-41C6-
94D7-EDB605459B46/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-10-14 16:18:49.221000-0400 FoodTracker[1946:46609] *** Terminating app 
due to uncaught exception 'NSUnknownKeyException', reason: 
'[<FoodTracker.ViewController 0x7fc93bf08b80> setValue:forUndefinedKey:]: 
this class is not key value coding-compliant for the key setDefaultLabelText.'

Anybody care to help?


Show source
| ios   | xcode   | swift   2017-10-14 23:10 1 Answers

Answers to this class is not key value coding-compliant for the key setDefaultLabelText.&#39; ( 1 )

  1. 2017-10-14 23:10

    I think that you have 2 outlets for the same label or textfield. You should check it in storyboard (right click on View Controller) . That's how it should look at the end of this part of the tutorial.

    Click here

    Make sure that there is no warnings.

Leave a reply to - this class is not key value coding-compliant for the key setDefaultLabelText.'

◀ Go back