title: Loaded nib but the view outlet was not set - Swift edition
body: <p>I have a project that is all in Objective C, except for my view controller, which is in Swift.</p>
  
  <p>When I run it, i get the error </p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception
    'NSInternalInconsistencyException', reason: '-[UIViewController
    _loadViewFromNibNamed:bundle:] loaded the "..." nib but the view outlet was not set.'</p>
  </blockquote>
  
  <p>So I opened up my nib file, look at "File's Owner", and I see that the view does not even show up as an outlet at all.<br>
  For my old view controller (objective c), the view outlet does show up.</p>
  
  <p>In my Swift view controller, I tried overriding the "view" variable from UIViewController in order to force it to be an @IBOutlet, but it complained about the "view" variable being of type UIView, complained about UIView?, and complained about UIView!.</p>
  
  <p>Here are simplified versions of </p>
  
  <p>my AppDelegate.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @class MyViewController;
  @class MyViewControllerSwift;
  
  @interface MSAppDelegate : UIResponder &lt;UIApplicationDelegate&gt;
  {
  }
  
  @property (strong, nonatomic) UIWindow *window;
  
  @property (strong, nonatomic) UIViewController *viewController;
  
  @end
  </code></pre>
  
  <p>AppDelegate.m</p>
  
  <pre><code>#import "MyAppDelegate.h"
  
  #import "MyViewController.h"
  #import "MySwift-Swift.h"
  #import &lt;UIKit/UIKit.h&gt;
  
  @implementation MyAppDelegate
  
  static BOOL USE_SWIFT_VIEW_CONTROLLER = YES;
  
  - (void)dealloc
  {
      [_window release];
      [_viewController release];
      [super dealloc];
  }
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
      self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
      // Override point for customization after application launch.
  
      id viewControllerPtr = nil;
      if(USE_SWIFT_VIEW_CONTROLLER)
      {
          viewControllerPtr = [MyViewControllerSwift alloc];
      }
      else
      {
          viewControllerPtr = [MyViewController alloc];
      }
  
      UIViewController* vController = nil;
      if(USE_SWIFT_VIEW_CONTROLLER)
      {
          vController = [[viewControllerPtr initWithNibName:@"MyViewControllerSwift" bundle:nil] autorelease];
      }
      else
      {
          vController = [[viewControllerPtr initWithNibName:@"MyViewController" bundle:nil] autorelease];
      }
  
      self.viewController = vController;
      self.window.rootViewController = self.viewController;
      [self.window makeKeyAndVisible];
  
      return YES;
  }
  </code></pre>
  
  <p>ViewController.swift</p>
  
  <pre><code>import Foundation
  import AVFoundation
  
  @objc class MyViewControllerSwift : UIKit.UIViewController {
  
      var player : AVFoundation.AVAudioPlayer?;
  
      @IBOutlet weak var myTextView : UITextView!;
  
      required init(coder aDecoder : NSCoder) {
          super.init(coder:aDecoder);
      }
  
      override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
          super.init(nibName:nibNameOrNil, bundle:nibBundleOrNil);
      }
  
      override func viewDidLoad() {
          super.viewDidLoad();
  
          println("Using MyViewControllerSwift");
      }
  
      deinit {
          //TODO
      }
  }
  </code></pre>
  
  <p>What do I need to do to get my view to display?</p>
  
  <p>Thanks.</p>
  
  <p>(Yes, this is a similar question to <a href="https://stackoverflow.com/questions/4763519/loaded-nib-but-the-view-outlet-was-not-set-new-to-interfacebuilder">Loaded nib but the view outlet was not set - new to InterfaceBuilder</a> but the view outlet does not show up.  )</p>