Swift NSUnknownKeyException FoodTracker

437 Views Asked by At

I'm just beginning to learn swift, and I have trouble understanding what the console is trying to tell me with this error. I'm following the Apple's guide to learn swift and in the section "Connect the UI to Code" I'm having the following problem:

2016-02-22 01:06:54.121 FoodTracker[20300:502503] <CATransformLayer: 0x7fab3973cb90> - changing property contentsCenter in transform-only layer, will have no effect
2016-02-22 01:06:54.127 FoodTracker[20300:502503] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FoodTracker.ViewController 0x7fab394a9a00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key setDefaultLabelText.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001040b7e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000105df7deb objc_exception_throw + 48
    2   CoreFoundation                      0x00000001040b7aa9 -[NSException raise] + 9
    3   Foundation                          0x00000001044809bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
    4   UIKit                               0x0000000104a63320 -[UIViewController setValue:forKey:] + 88
    5   UIKit                               0x0000000104c91f41 -[UIRuntimeOutletConnection connect] + 109
    6   CoreFoundation                      0x0000000103ff84a0 -[NSArray makeObjectsPerformSelector:] + 224
    7   UIKit                               0x0000000104c90924 -[UINib instantiateWithOwner:options:] + 1864
    8   UIKit                               0x0000000104a69eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
    9   UIKit                               0x0000000104a6a816 -[UIViewController loadView] + 178
    10  UIKit                               0x0000000104a6ab74 -[UIViewController loadViewIfRequired] + 138
    11  UIKit                               0x0000000104a6b2e7 -[UIViewController view] + 27
    12  UIKit                               0x0000000104941ab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
    13  UIKit                               0x0000000104942199 -[UIWindow _setHidden:forced:] + 282
    14  UIKit                               0x0000000104953c2e -[UIWindow makeKeyAndVisible] + 42
    15  UIKit                               0x00000001048cc663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
    16  UIKit                               0x00000001048d2cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
    17  UIKit                               0x00000001048cfe7b -[UIApplication workspaceDidEndTransaction:] + 188
    18  FrontBoardServices                  0x0000000107c8c754 -[FBSSerialQueue _performNext] + 192
    19  FrontBoardServices                  0x0000000107c8cac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    20  CoreFoundation                      0x0000000103fe3a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    21  CoreFoundation                      0x0000000103fd995c __CFRunLoopDoSources0 + 556
    22  CoreFoundation                      0x0000000103fd8e13 __CFRunLoopRun + 867
    23  CoreFoundation                      0x0000000103fd8828 CFRunLoopRunSpecific + 488
    24  UIKit                               0x00000001048cf7cd -[UIApplication _run] + 402
    25  UIKit                               0x00000001048d4610 UIApplicationMain + 171
    26  FoodTracker                         0x0000000103ed947d main + 109
    27  libdyld.dylib                       0x000000010690092d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Also, this is the code I'm running:

import UIKit

class ViewController: UIViewController {

    //MARK: Propierties
    @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"
    }
}

Thank you in advance for your help. Looking forward to it.

1

There are 1 best solutions below

0
On

Already solved my problem. As I was just starting to code, I tried copying and pasting what I've written into a new file and it works perfectly now. No issues at all. It might have been some bug with the config. Thanks anyway.