When you just at start of becoming great iOS Developer you already have faced or definitely will face with wide range of crashes. It can be very frustrating and can be big problem on your way on learning iOS development. I think every dev has faced and knows this XCode statement: this class is not key value coding-compliant for the key.
Full text of this crash can seem like the following:
*** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[<UIViewController 0xXXXXXX> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX.’
This crash can be quite annoying and it’s unclear what to do with that. But the issue is pretty simple to resolve. Let’s take a look on common reasons:
Outlet removed in the code, but is still set in Storyboard/Xib
You can have the situation like that.. You have some element in Storyboard/Xib that was previously bind to your View Controller but now you removed it from code and didn’t remove it from your interface file. Double check that you don’t have situation like on following screenshots:
|Outlet is connected to ViewController||Outlet is commented out in the code|
Class Name in Storyboard/Xib is wrong
It’s common mistake that class name set in StoryBoard / Xib is wrong. Below is example… just a misspelled word can cause this annoying crash:
|Name is set to ViwController||Class name is View Controller|
Error after copying a View Controller
Somehow it can appear after you have copied your View Controller. Please double check View Controller’s connection inspector each time you’re copying view controller in order to avoid such situations as below:
To resolve “class is not key value coding-compliant for the key” issue you just need to click on close button (x) of problem outlet and re-bind it one more time.
Also please make sure that you have done full clean + rebuild after resolving such issues. Xcode is not perfect IDE and it still has a huge issue that can be resolved simply by clean ( Shift + CMD + K ) and build ( CMD + B )
Thanks for reading!