This class is not key value coding-compliant for the key cancel

this class is not key value coding-compliant for the key swift 4
this class is not key value coding-compliant for the key swift 5
this class is not key value coding-compliant for the key view xib
this class is not key value coding-compliant for the key objective c
this class is not key value coding-compliant for the key uitableviewcell
this class is not key value coding-compliant for the key firebase
this class is not key value coding-compliant for the key containerview
this class is not key value coding compliant for the key operator

I keep getting this error: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FoodTracker.MealViewController 0x7faa9ed189d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cancel.'

I'm trying to complete the Apple developer guide to getting started with iOS apps. My code and storyboard looks exactly like theirs does in the example file. I'm hoping that a fresh eye might be able to see something I am not?

import UIKit
import os.log

class MealViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    //MARK: Properties
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var photoImageView: UIImageView!
    @IBOutlet weak var ratingControl: RatingControl!
    @IBOutlet weak var saveButton: UIBarButtonItem!
    /*
     This value is either passed by 'MealTableViewController' in
     'prepare(for:sender) or constructed as part of adding a new meal.
    */
    var meal: Meal?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Handle the text field's user input through delegate callbacks
        nameTextField.delegate = self

        // Enable save button only if text field has valid Meal name
        updateSaveButtonState()
    }

    //MARK: UITextFieldDelegate
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        // Hide the keyboard
        textField.resignFirstResponder()
        return true
    }
    func textFieldDidEndEditing(_ textField: UITextField) {
        updateSaveButtonState()
        navigationItem.title = textField.text
    }
    func textFieldDidBeginEditing(_ textField: UITextField) {
        // Disable save button while editing
        saveButton.isEnabled = false
    }

    //MARK: UIImagePickerControllerDelegate
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        // Dismiss the picker if the user canceled
        dismiss(animated: true, completion: nil)
    }
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        // The info dictionary may contain multiple representations of the image. You want to use the original.
        guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
            fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
        }
        // Set photoImageView to display the selected image
        photoImageView.image = selectedImage
        // Dismiss the picker
        dismiss(animated: true, completion: nil)
    }

    //MARK: Navigation
    @IBAction func cancel(_ sender: UIBarButtonItem) {
        dismiss(animated: true, completion: nil)
    }


    // Configure view controller before it's presented
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        super.prepare(for: segue, sender: sender)

        // Configure destination view controller only when save button pressed
        guard let button = sender as? UIBarButtonItem, button === saveButton else {
            os_log("The save button was not pressed, cancelling", log: OSLog.default, type: .debug)
            return
        }

        let name = nameTextField.text ?? ""
        let photo = photoImageView.image
        let rating = ratingControl.rating

        // Set meal to be passed to MealTableViewController after unwind segue
        meal = Meal(name: name, photo: photo, rating: rating)
    }

    //MARK: Actions
    @IBAction func selectImageFromPhotoLibrary(_ sender: UITapGestureRecognizer) {
        // Hide the keyboard
        nameTextField.resignFirstResponder()
        // UIImagePickerController is a view controller that lets a user pick media from their photo library
        let imagePickerController = UIImagePickerController()
        // Only allow photos to be picked, not taken
        imagePickerController.sourceType = .photoLibrary
        // Make sure ViewController is notified when the user picks an image
        imagePickerController.delegate = self
        present(imagePickerController, animated: true, completion: nil)
    }

    //MARK: Private Methods
    private func updateSaveButtonState() {
        // Disable the save button if the text field is empty
        let text = nameTextField.text ?? ""
        saveButton.isEnabled = !text.isEmpty
    }
}

There are a few other files, but please just let me know what you need because I am very new to Swift/XCode and not sure what to provide/not provide.

This means that you have something on your storyboard connected to the IBOutlet called cancel but you don't have this IBOutlet in your class. So compiler can't find Key cancel(it means property) in your class. You should find that button(i think it's a UIButton because of the name) in storyboard, click right mouse button on it and click "x" to delete that connection. Or you might want to delete this button at all. Or you might want to add this IBOutlet to your class.

How to fix Error: this class is not key value coding-compliant for the , You have your storyboard set up to expect an outlet called tableView but the actual outlet name is myTableView . If you delete the connection in  So whenever you get the error: “this class is not key value coding-compliant” you should first and foremost think if you recently changed something that has a connection to the Main.storyboard or to the design file. For the most time, there is an unbroken connection to something that no longer exists in the code.

I agree with what Alex Shubin mentioned in his answer, an actionable solution like "look for any connections that don’t exist anymore and delete them". I was having the same issue and his suggestion fixed that bug. For those who are new to programming, and Xcode like me, a little more information on how to locate the x button in storyboard might be helpful.

Click on the yellow circle at the top of the view controller in storyboard.

Then show the connections inspector in the upper right of the utilities bar. The connections inspector is the menu on the far right, a circle with a right pointing arrow. Click that, and you should see all the connections for that view controller.

I'm including a screen shot of what that looks like in my app.

Fixing "This Class is not Key Value Coding-Compliant for the Key , How to fix: this class is not key value coding-compliant for the key. Here you'll see how to resolve it. 2 labels 2 textfields 2 button (login and cancel). What is this trying to tell me? It happy until it tries to launch. com.intel.inde.moe.natj.objc.ObjCException: [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cancel.

Check for the module name under "Identity Inspector". Either module name has to be selected or "Inherit Module from Target" has to be checked. If there are multiple modules, select the appropriate one.

FIXED: this class is not key value coding-compliant for the key , Hi i get this error : this class is not key value coding-compliant for the key ibCalendarDataSource.' i follow your set up video step by step and  this class is not key value coding-compliant for the key Here is how you can quickly find the problematic object inside the storyboard without manually going through all of the elements: 1.

this class is not key value coding-compliant for the key , reason: '[<UIViewController 0x143d485f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key drawerContentContainerView. How To Make an iPhone App - Ep 10 - Class Not Key Value Coding Compliant (Xcode 8, Swift 3, iOS 10) - Duration: 6:57. London App Brewery 1,833 views

UIViewController not key value coding-compliant · Issue #29 · 52inc , '[<UIApplication 0x7fa8cc800110> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key calculateButtonItself.'. To learn other Xcode tips and Tricks, check our the below three blog posts of mine which contain many more useful Xcode video tutorials: Xcode Tips and Tricks to Work with Layout Constraints and Views

this class is not key value coding-compliant fo |Apple Developer , The error “This class is not key value coding-compliant for the key” is a common problem for iOS developers which causes an app to crash right  [Jblack Solution][IOS] this class is not key value coding-compliant for the key save. Cancel Unsubscribe. Working Subscribe Subscribed this class is not key value coding-compliant for

Comments
  • Delete the existing cancel IBAction and drag and drop again the cancel action in class. because it's not connected with storyboard somehow.
  • I had the same issue. It's happened because I control + dragged the cancel button into the Properties section first, just as all the previous steps had me do. When I realized I was supposed to control + drag this view to the Navigation section, I deleted the outlet in MealViewController. This didn't delete the link from the storyboard, which is causing the crash since the outlet doesn't exist now. You need to delete the link using the steps outlined in the answers below
  • Best answer! Thanks
  • My last view controller randomly didn't have this selected and its been driving me crazy trying to figure out why my simple IBoutlets to labels were crashing. Thank you!
  • The "Inherit Module from Target" solved it. Thank you! This was killing me for hours!