Tuesday, 10 October 2017

ios - Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?

itemprop="text">

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:
'[ setValue:forUndefinedKey:]: this class is not key
value coding-compliant for the key
XXX.'



class="post-text" itemprop="text">
class="normal">Answer



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



I downloaded your project.




The error you are getting is





'NSUnknownKeyException', reason: '[
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.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...