xcode: class is not key value coding-compliant

15,748

Solution 1

This is due to FoodTracker VC in storyboard has an outlet created but not connected.

How to resolve the issue? Follow these steps.

  1. Open your storyboard, click on view controller below view controller scene.
  2. Check for all outlets for ViewController.
  3. Remove those outlets created and are not connected to ViewController.swift implementation file.

Keep me updated on the same.

Solution 2

Check your connection to @IBAction with this steps below:

In the storyboard: enter image description here enter image description here

In your view controller:

enter image description here

Updated:

In your case, you should remove connection in Reference Outlets because you connect it to the label outlet.

Share:
15,748
Ginso89
Author by

Ginso89

Updated on June 09, 2022

Comments

  • Ginso89
    Ginso89 almost 2 years

    I'm currently working myself through this tutorial: https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ConnectTheUIToCode.html#//apple_ref/doc/uid/TP40015214-CH22-SW1 After creating the function for the button(at ~2/3 on the page) I tried running the code and got the Exception:

    2017-12-08 11:24:31.343183+0100 FoodTracker[2159:154603] *** 
    
    Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FoodTracker.ViewController 0x7fea6f406820> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key setDefaultLabelText.'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x0000000109d7512b __exceptionPreprocess + 171
        1   libobjc.A.dylib                     0x00000001060fcf41 objc_exception_throw + 48
        2   CoreFoundation                      0x0000000109d75079 -[NSException raise] + 9
        3   Foundation                          0x0000000105b1ba63 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
        4   UIKit                               0x0000000106b39117 -[UIViewController setValue:forKey:] + 87
        5   UIKit                               0x0000000106e2ac2d -[UIRuntimeOutletConnection connect] + 109
        6   CoreFoundation                      0x0000000109d183cd -[NSArray makeObjectsPerformSelector:] + 317
        7   UIKit                               0x0000000106e295e3 -[UINib instantiateWithOwner:options:] + 1856
        8   UIKit                               0x0000000106b403ff -[UIViewController _loadViewFromNibNamed:bundle:] + 383
        9   UIKit                               0x0000000106b40d2b -[UIViewController loadView] + 177
        10  UIKit                               0x0000000106b4105c -[UIViewController loadViewIfRequired] + 195
        11  UIKit                               0x0000000106b418b9 -[UIViewController view] + 27
        12  UIKit                               0x0000000106a0c7cf -[UIWindow addRootViewControllerViewIfPossible] + 122
        13  UIKit                               0x0000000106a0ced7 -[UIWindow _setHidden:forced:] + 294
        14  UIKit                               0x0000000106a1fe54 -[UIWindow makeKeyAndVisible] + 42
        15  UIKit                               0x00000001069928b8 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4737
        16  UIKit                               0x0000000106997aeb -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720
        17  UIKit                               0x0000000106d616f8 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924
        18  UIKit                               0x00000001071374c8 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
        19  UIKit                               0x0000000106d612f1 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249
        20  UIKit                               0x0000000106d61b6b -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 696
        21  UIKit                               0x00000001076dfa69 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262
        22  UIKit                               0x00000001076df922 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444
        23  UIKit                               0x00000001073bc9c8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221
        24  UIKit                               0x00000001075bbb06 _performActionsWithDelayForTransitionContext + 100
        25  UIKit                               0x00000001073bc88b -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231
        26  UIKit                               0x0000000107136b25 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
        27  UIKit                               0x000000010699636a -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523
        28  UIKit                               0x0000000106f71605 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369
        29  FrontBoardServices                  0x000000010bc38cc0 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338
        30  FrontBoardServices                  0x000000010bc417b5 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235
        31  libdispatch.dylib                   0x000000010ae9733d _dispatch_client_callout + 8
        32  libdispatch.dylib                   0x000000010ae9c9f3 _dispatch_block_invoke_direct + 592
        33  FrontBoardServices                  0x000000010bc6d498 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
        34  FrontBoardServices                  0x000000010bc6d14e -[FBSSerialQueue _performNext] + 464
        35  FrontBoardServices                  0x000000010bc6d6bd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
        36  CoreFoundation                      0x0000000109d18101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        37  CoreFoundation                      0x0000000109db7f71 __CFRunLoopDoSource0 + 81
        38  CoreFoundation                      0x0000000109cfca19 __CFRunLoopDoSources0 + 185
        39  CoreFoundation                      0x0000000109cfbfff __CFRunLoopRun + 1279
        40  CoreFoundation                      0x0000000109cfb889 CFRunLoopRunSpecific + 409
        41  GraphicsServices                    0x000000010c5019c6 GSEventRunModal + 62
        42  UIKit                               0x00000001069995d6 UIApplicationMain + 159
        43  FoodTracker                         0x00000001057e7b67 main + 55
        44  libdyld.dylib                       0x000000010af13d81 start + 1
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb) 
    

    Here is my Code:

    Screenshot

    And the connections inspector of the button:

    enter image description here

  • biloshkurskyi.ss
    biloshkurskyi.ss over 6 years
    @Ginso89 tap on your ViewController(in the left side of storyboard), after in the Connection inspector you should find it.