Search code examples
iosxcodetargetnsunknownkeyexception

˜this class is not key value coding-compliant for the key˜ when creating a new Target


I have a big base project for iOS done in Swift. Now I was trying to create different client version by creating a new Targets:

  • BaseProject (Works just fine, unless I change it's name)
  • Client1 (NSUnknownKeyException after launch screen).

The base project runs just fine. But I get the following NSUnknownKeyException when I switch for the new target:

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

"textConfirmPassword" is a reference of a Text Field from my main.storyboard.

  • I checked Referencing outlets and that doesn't seem to be the problem.
  • I checked Target Membership of the Text Field.
  • I Recreated the outlet reference.
  • I deleted the reference, created a hard coded text field that doesn't appear on the storyboard just so the code would compile. The exception went to a different Text Field (textEmail).

Before doing all this, I created a sample project using an image and a referenced label. The versioning worked just fine.


Solution

  • I found what was wrong. Something really simple that I can't believe it took me so long to figure out. The first view controller had a module selected (when it was not supposed to have any). For that reason, whenever I ran a different target it would not find the view's elements.