title: Nib/Xib object lifecycle
body: <p>Right now I have a rootViewController that calls another ViewController that is a nib file via:</p>
  <pre><code>self.popViewController = PopViewController(nibName: &quot;PopUpViewController_iPhone6Plus&quot;, bundle: bundle)
  </code></pre>
  <p>Where this init is:</p>
  <pre><code> override public init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
      super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  }
  </code></pre>
  <p>After rootViewController instantiates PopViewController it brings it up via:</p>
  <pre><code>self.popViewController.showInView(self, animated: true)
  </code></pre>
  <p>Where showInView is:</p>
  <pre><code> func showInView(myRootViewController : MyRootViewController!, animated: Bool)
  {
      self.myRootViewController = myRootViewController
      myRootViewController.view.addSubview(self.view)
      myTextField.delegate = self
      
      if animated
      {
          self.showAnimate()
      }
  }
  </code></pre>
  <p>Where myTextField is an IBOutlet for PopViewController. I realised that if I put <code>myTextField.delegate = self</code> before <code>   myRootViewController.view.addSubview(self.view)</code> then I get an error: <code>fatal error: unexpectedly found nil while unwrapping an Optional value</code> but if I put it afterwards everything is fine.</p>
  <p>I've looked at the documentations for the <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html" rel="nofollow noreferrer">Nib files</a> and my question is:</p>
  <p>Is the reason why I'm getting the error when I put <code>myTextField.delegate = self</code> before <code>myRootViewController.view.addSubview(self.view)</code> because the IBOutlets don't get connected before the nib's view is shown?</p>
  <p>Also:
  Why does loading the nib via:
  <code>self.popViewController = NSBundle.mainBundle().loadNibNamed(&quot;PopViewController_iPhone6&quot;, owner: PopViewControllerSwift.self, options: nil).first as! PopViewControllerSwift</code></p>
  <p>throw an error:</p>
  <p><code>'NSUnknownKeyException', reason: '[&lt;DeckWheel.PopUpAddDeckViewControllerSwift 0x10026cbe0&gt; setValue:forUndefinedKey:]</code></p>