title: Loading a Custom View Controller from a XIB to Main View Controller Gives NSUnknownKeyException
body: <p><strong>UPDATE : Answer</strong></p>
  
  <p>I posted my answer below which solved this problem for me. Reason for the issue is entirely different to the post that has been suggested.</p>
  
  <p><strong>Original Question:</strong></p>
  
  <p>I am trying to load a UIView from a xib file which is defined as a ViewController. </p>
  
  <pre><code>        if let overlayView = (Bundle.main.loadNibNamed("CalendarViewController", owner: self, options: nil)?.first as? JTAppleCalendarView) {
          self.navigationController?.view.addSubview(overlayView)
      }
  </code></pre>
  
  <p>However, every time I run the project, I get a unknown key exception. </p>
  
  <pre><code>Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[&lt;MyApp.ViewController 0x7feac8607cc0&gt; setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key calendarView.'
  </code></pre>
  
  <p>I have one view in the xib file which I am connecting to its owner (viewcontroller) through a IBOutlet. This key is given as the one that is causing the error. However, when I checked the UIView's referencing outlets, they are in good standing. </p>
  
  <p>I tried removing the reference and re-adding it and also trying to load the xib by specifying the owner to the xib's view controller. Still no luck.</p>
  
  <p><strong>Update</strong>: References</p>
  
  <p><a href="https://i.stack.imgur.com/7elzt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7elzt.png" alt="enter image description here"></a></p>
  
  <p>Also the connections portion of the xib's xml:</p>
  
  <pre><code>            &lt;connections&gt;
              &lt;outlet property="calendarView" destination="dqi-m5-FXD" id="mAV-5Y-SXl"/&gt;
          &lt;/connections&gt;
  </code></pre>
  
  <p><strong>Related code:</strong></p>
  
  <p><a href="https://github.com/cooderatgit/CalendarApp" rel="nofollow noreferrer">https://github.com/cooderatgit/CalendarApp</a></p>