How to programatically add views to NSWindow (or NSView)?
<p>I have this code in my ViewController. The view I'm adding programatically is nowhere to be seen however.</p>

<pre><code>override func viewDidLoad() {
    super.viewDidLoad()

    let f: NSRect = NSMakeRect(0, 0, 200, 200)
    let v: NSView = NSView(frame: f)
    v.layer?.backgroundColor = NSColor.yellowColor().CGColor
    self.view.addSubview(v)

}
</code></pre>

<p>Additionally I tried creating a custom NSWindowController and set that as the Custom Class of my main Window in the interface builder storyboard. There I have the following code:</p>

<pre><code>override func windowDidLoad() {
    super.windowDidLoad()

    let f: NSRect = NSMakeRect(0, 0, 200, 200)
    let v: NSView = NSView(frame: f)
    v.layer?.backgroundColor = NSColor.yellowColor().CGColor
    self.window?.contentView?.addSubview(v)

}
</code></pre>

<p>This does not work either :/ </p>

<p>I even tried setting <code>v.wantsLayer = true</code> as one of the answers I found online suggested, however that seemed strange from the get go and of course did nothing.</p>

<p>What am I doing wrong here? </p>