title: In OS X app, how to use auto layout when a window is created programmatically?
body: <p>My OS X App tries to create a window programmatically as below (suggested by another SO question I saw earlier):</p>
  
  <pre><code>class MyViewController: NSViewController {
  
      override func loadView() {
  
          let view = NSView(frame: NSMakeRect(0,0,300,100))
          view.wantsLayer = true
          view.layer?.borderWidth = 2
          view.layer?.borderColor = NSColor.red.cgColor
          self.view = view
     }
  }
  
  let viewController = MyViewController()
  let window = NSWindow(contentRect: someFrame, styleMask: [.resizable, .closable, .miniaturizable, .titled], backing: NSBackingStoreType.buffered, defer: false)
  
  window.contentView?.addSubview(viewController.view)
  window.makeKeyAndOrderFront(nil)
  </code></pre>
  
  <p>I can successfully create windows by the code above. However, my question is... how to make the view created in <code>loadView</code> inside the view controller to be the same size as the window's content view?</p>
  
  <p>Right now, it creates the view with fixed numbers (0, 0, 300, 100). How to make this view to be the same size as the window by using Auto layout, so when the window is resized, this view will resize automatically too?</p>