Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X error?
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.
One more possible reason
(In my case) Extension of UIView with bindable properties and setting values for those bindable properties (i.e. shadow, corner radius etc.) then remove those properties from UIView extension (for some reason) but the following <userDefinedRuntimeAttributes>
remained in xml (of foo.storyboard
):
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="shadowColor">
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="shadowOpacity">
<real key="value" value="50"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="point" keyPath="shadowOffset">
<point key="value" x="5" y="5"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="shadowRadius">
<real key="value" value="16"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="borderWidthValue">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
Solution: Right click on foo.storyboard
> Open as Source Code > search by keyPath (i.e. shadowRadius) > Delete the </userDefinedRuntimeAttributes>
that causing the problem
setValue:forUndefinedKey: this class is not key value coding-compliant for the key
Such inexplicable exceptions are often a result of an unclean xib
file.
Open the xib
in xcode, select File's Owner and click on the "Connection Inspector" (upper right arrow), to see all outlets at once.
Look for !
s which indicates a missing outlet.
How do I solve a 'NSUnknownKeyException' ... setValue:forUndefinedKey:]: ...not key value coding compliant
Look in your storyboard or xib (whichever you're using) for the ViewControllerWelcome
object. The most likely source of this error is that something has a connection to an action or outlet called done
that doesn't exist in the code for that class.
NSUnknownKeyException this class is not key value coding-compliant for the key
"this class is not key value coding-compliant for the key pause" usually means you have a referencing outlet problem. Look in the Connections Inspector for your different buttons. You may likely either have:
2 referencing outlets for one button and the program does not know which ne to use, etc.
I ran the code hooking up 1 label to an IBOutlet and three buttons (play, pause, reset), one to each IBAction, and it ran perfectly.
Swift setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
Okay I just faced the same issue and it was due to having multiple targets. I couldn't figure out why it would run perfectly fine in some instances, yet not others. The issue is actually with the Module definition on the view controller, I'm guessing that this may explain why when you completely recreate the controller the issue seems magically fixed. On mine I had the Module set to one of my targets, so when I ran a second target it wasn't associated. If you have multiple targets make sure you empty the Module box on the VC that crashes (on your storyboard) and tick Inherit Module From Target.
Hope this helps
How to fix Error: this class is not key value coding-compliant for the key tableView.'
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 the storyboard and reconnect to the right variable name, it should fix the problem.
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X error?
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.
One more possible reason
(In my case) Extension of UIView with bindable properties and setting values for those bindable properties (i.e. shadow, corner radius etc.) then remove those properties from UIView extension (for some reason) but the following <userDefinedRuntimeAttributes>
remained in xml (of foo.storyboard
):
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="shadowColor">
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="shadowOpacity">
<real key="value" value="50"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="point" keyPath="shadowOffset">
<point key="value" x="5" y="5"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="shadowRadius">
<real key="value" value="16"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="borderWidthValue">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
Solution: Right click on foo.storyboard
> Open as Source Code > search by keyPath (i.e. shadowRadius) > Delete the </userDefinedRuntimeAttributes>
that causing the problem
Related Topics
iOS Swift Navigate to Certain Viewcontroller Programmatically from Push Notification
How to Use Uicolorfromrgb in Swift
Swift 3.0 Result of Call Is Unused
How to Fade a Uivisualeffectview And/Or Uiblureffect in and Out
Uilabel Text Truncation VS. Line Breaks in Text
Proper Usage of the Alamofire's Urlrequestconvertible
iOS 7 Uitableview: How to Remove Space Between Navigation Bar and First Cell
Codesign Returned Unknown Error -1=Ffffffffffffffff
Switui - Two Navigationlink in a List
How to Launch the iOS Simulator from Terminal
Limit Number of Characters in Uitextview
Get User Profile Details (Especially Email Address) from Twitter in iOS
iPhone Uibutton - Image Position
How to Respond to Push Notification View If App Is Already Running in the Background
What's the Best Way to Add a Drop Shadow to My Uiview