ios - uitableviewcell - valueforundefinedkey:]: this class is not key value coding-compliant for the key

What does this mean? “'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X” (20)

You may have a bad connection in your xib.

I've had this error many times. While TechZen's answer is absolutely right in this case, another common cause is when you change the name of a IBOutlet property in your .h/.m which you've already connected up to File's Owner in the nib.

From your nib:

  1. Select the object in IB and go to the 'Connections Inspector'.
  2. Under 'Referencing Outlets' make sure that your object isn't still connected to the old property name... if it is, click the small 'x' to delete the reference and build again.

Another common cause if you are using Storyboard, your UIButton might have more then one assignings (Solution is almost the same as for nib):

  1. Open your storyboard and right click the UIButton
  2. You will see that there is more than one assign/ref to this button. Remove one of the "Main..." greyed windows with the small "x":

I'm trying to link a UILabel with an IBOutlet created in my class.

My application is crashing with the following error. What does this mean? How can I fix it?

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX.'

Your view controller may have the wrong class in your xib.

I downloaded your project.

The error you are getting is

'NSUnknownKeyException', reason: '[<UIViewController 0x3927310> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key string.'

It is caused by the Second view controller in MainWindow.xib having a class of UIViewController instead of SecondView. Changing to the correct class resolves the problem.

By the way, it is bad practice to have names like "string" in Objective-C. It invites a runtime naming collision. Avoid them even in once off practice apps. Naming collisions can be very hard to track down and you don't want to waste the time.

Another possible reason for this error: when copying & pasting elements from one controller into another, Xcode somehow keeps that link to the original controller, even after editing & relinking this element into the new controller.

Another possible reason for this error:

Bad Outlet.

You have either removed or renamed an outlet name in your .h file.

Remove it in .xib or .storyboard file's Connection Inspector.

My fix was similar to Gerard Grundy's. In creating a custom UITableViewCell using an XIB, I had mistakenly applied the Custom Class name to the File's Owner instead of to the UITableViewCell. Applying the class to the UITableViewCell on the canvas and connecting my IBOutlet properties to it solved the issue.

"Module" property of View Controller in the Identity Inspector might be different than what you expected. Also make sure that new classes are added to your target list.

Another "not compliant" issue I found was when I managed to have two copies of a class for some reason.

I was adding keys to the wrong copy. Interface Builder still saw the keys and let me hook up to them, but at runtime it was using the other copy of the class that didn't have the new keys.

To find which was the "right" copy I used XCode's cmd-click on the class name elsewhere to jump to the correct copy, then I killed off the bad unused copies (after bringing over my edits from the un-used copy first).

Moral of the story: duplicate class files are bad.

I got the same problem. I did resetting the simulator. Removing and adding button control. and finally made a clean. :) Thanks to . Some how my code became ok and starting working.

I had exact same error message and thanks (!!) to Kira from I was able to solve the challenge. I only found her site after googling and stacking over all these threads. I'm now posting here for the next one that comes to and has the same challenge I had since that person will most likely come to this thread over Google.

I realized, that I wrongly made this:

UIViewController *deviceViewController = [[UIViewController alloc] initWithNibName:@"DeviceViewController" bundle:nil];

Instead of THIS:

DeviceViewController *deviceViewController = [[DeviceViewController alloc] initWithNibName:@"DeviceViewController" bundle:nil];



Was the name of my Class also known as


You'll have to

"import DeviceViewController.h"

in your implementation (.m File) where you want to call e.g. another UIViewController.

I am absolutely not sorry if I am only stating the obvious for beginners like me and may get down votes as this is not exactly related to the question but I was searching 4 (?!?) hours straight now for the answer to these error message. If I can spare this to 1 or 2 people that'd be great :)

PS: For those interested in how the code continues for loading the other UIViewController:

    [self presentViewController:deviceViewController animated:YES completion:nil];

I had the same problem and while TechZen's answer may indeed be amazing I found it hard to apply to my situation.

Eventually I resolved the issue by linking the label via the Controller listed under Objects (highlighted in the image below) rather then via the File Owner.

Hope this helps.

I had this error when I was trying to implement a custom ViewCell for a table. When I highlighted View controller for the XIB and connected to the elements in the CellView caused the error " this class is not key value coding-compliant for the key" once I deleted these it got rid of the error.

Delete the connections in the below image.

Just make sure that you only have the connections with the Table View Cell. To check click on table view cell and in INSPECTOR look for your connections.

I had to delete the app from the simulator/iPhone to get rid of this error.

I was getting this error with storyboards. The above solution didn't seem to be the problem so I ended up deleting the view controller and adding it back in again (and of course reconnecting the segue and reassigning the class) which fixed it. I don't know what it really was, but I had renamed the associated view controller class shortly before this started, so maybe that had hosed something.

If it is an iPhone only app, not a universal one, make sure the following field is empty:

Targets > Summary > iPhone/iPod Deployment Info > Main Interface

If you specify an xib there it crashes.

In my case, this was caused by referencing the wrong Nib:

BMTester *viewController = [[BMTester alloc] initWithNibName:@"WrongNibName" bundle:nil];

In my case. I didn't have missing outlets in xib-files after merging.

Shift + Command + K

solved my problem. I cleaned my project and rebuilt.

Just to add to this, because I was getting this error as well. Going through all these answers most seem to apply to working with the UI and storyboard stuff. I know the original poster did seem to be working with the UI but when searching for possible reasons for this error mostly all questions lead back to this question with those others being closed as duplicates or simply having issues with connecting things in a storyboard so I will add my solution.

I was working on coding a web service in Swift 2. I had built all the needed proxy objects and stubs. As I looped through the returned XML I was dynamically instantiating my objects, which all came from NSObject and using setValue:forKey on them. Every time setValue:forKey tried to set a property it blew up with this error.

I had a switch statement for each type I was dealing with (e.g. Bool?, CShort?, String?) and for each XML node I went through and checked what the type was on the object and then converted the value to that type and attempted to set it with setValue:forKey.

Eventually I started commenting out all these setValue:forKey lines and found that my default switch statement case did work for String?.

I finally figured out that you can't use optional swift types with setValue:forKey unless they have a direct mapping to an Objective-C type like String? or NSNumber?. I ended up changing all CShort? types to NSNumber? since that has a direct mapping. For Bool? in my case it was fine for me to just use Bool and initialize it to false. Others may not have that luxury.

Anyway what a headache that was so hopefully this helps someone else who has a similar problem and keeps getting redirected to this question and saying to themselves, "I am not doing anything in UI!!".

So lastly to reiterate one more time Key-Value Coding does not work with optionals. Below I ended up finding somewhere but I forget where so to whoever posted this I apologize and would give credit if I remembered where I found this but it saved my life:

You cannot use KVC on an Optional Int property, because KVC is Cocoa / Objective-C, and Objective-C cannot see an Optional Int - it is not bridged to Objective-C. Objective-C can only see types that are bridged to Objective-C:

class types that are derived from NSObject

class types that are exposed with @objc

Swift structs that are bridged

Looking over the other answers it seems like there are a lot of things that can cause this error. Here is one more.

If you

  • have a custom view
  • added an @IBInspectable property
  • and then later deleted it

Then you may also get an error similar to

Failed to set (xxx) user defined inspected property on [Your Custom View] ...: this class is not key value coding-compliant for the key [xxx].

The solution is to delete the the old property.

Open the Identity inspector for your class, select the property name under User Defined Runtime Attributes, and press the minus button (-).

That might be the case of referencing a component from Xib Interface that you have renamed or delete. Re-referencing works for me.

This error indicates that an already connected Interface Builder object is removed/renamed in its owner's source (File's Owner).

Control-click on the Files's Owner in the Interface Builder if you see a exclamation mark you need to fix that.

In the picture below you can see that "aRemovedView" has an exclamation mark on its right, that's because I removed the IBOutlet view object while it was already connected in the IB.

This gives the following error: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key aRemovedView.'

This happens to me when my view controller originally had an .xib file, but now is created programmatically.

Even though I have deleted the .xib file from this project. The users iPhone/iPad may contain an .xib files for this viewcontroller.

Attempting to load an .xib file usually causes this crash:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x18afe0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key welcomeLabel.'

Solution when creating it programmatically may be this:

-(void)loadView {
    // Ensure that we don't load an .xib file for this viewcontroller
    self.view = [UIView new];

This was happening to me only when debugging on a device (iPhone). The iOS Simulator was working OK. Doing a "Product->Clean" from Xcode seemed to solve the problem, but I have no idea why.