5

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
CFlux
  • 346
  • 4
  • 9
  • If you're absolutely sure there's no unconnected outlets (checked via the connections inspector) then just cleaning then exiting and restarting Xcode has fixed this for me several times in the past. Its amazing how many Xcode issues can be resolved by a restart of it. – Gruntcakes May 25 '16 at 15:54
  • I did that already. I recreated all connections and restarted xcode. No such luck. – CFlux May 25 '16 at 15:57

3 Answers3

4

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.

CFlux
  • 346
  • 4
  • 9
  • You've described my problem exactly (made a new target, old one builds, new one crashes with this exception, but it's not the outlet (I can disconnect it and it just crashes on the next outlet). I can't figure out what you mean though. What is the "first view controller" (the root?) What is "had a module selected" (target membership?) – SimplGy Dec 06 '16 at 01:26
  • I had the same exact problem. Thanks for pointing out. @SimplGy when you select an implementation file, in Xcode you can find a section "Target Membership" in the File Inspector. That's where your target should be enabled. – Franklin Jun 30 '17 at 14:35
4

I finally found the issue, for few view controllers in my storyboard->Identity Inspector->Inherit Module From Target wasn't selected that is why an error came in the newly created target.

enter image description here

Check "Inherit Module From Target" for view controllers

Mohit Kumar
  • 2,898
  • 3
  • 21
  • 34
  • Thank you, I had this same issues and that was definitely the solution. Pulled my hair out for an hour or two before I found your response! – Scott D Aug 27 '20 at 03:30
  • Hi, I have the same problem but actually, I have "Inherit Module From Target" checked and the outlet connected well and the class set well too. – Ridney Mar 15 '21 at 10:40
0

In my case I had to set the custom class name for the view itself from Inspector. I was setting only file owner's class and connecting with it but was getting same error. enter image description here

Ammar Mujeeb
  • 1,222
  • 18
  • 21