NSTextField label: dynamically change content and grow width to fit
<p>If I drag a <code>Label</code> (of class <code>NSTextField</code>) into a view in Interface Builder, and then attempt to set its <code>stringValue</code> dynamically like so:</p>

<pre><code>self.testingLabel.stringValue = "Labels are really really really long"
</code></pre>

<p>Then most of the label will be cut off.</p>

<p><a href="https://i.stack.imgur.com/u5uaa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u5uaa.png" alt="cut off text"></a></p>

<p>How can I make the label grow to fit its content without wrapping/scrolling?</p>

<p>I have tried using this custom class but it doesn't work.</p>

<pre><code>class AutogrowTextField: NSTextField {
    override var intrinsicContentSize: NSSize {
        get {
            var frame = self.frame;
            frame.size.width = CGFloat.max;

            // Calculate new height within the frame
            // with practically infinite height.
            let width = self.cell!.cellSizeForBounds(frame).width

            Swift.print(width)
            NSBeep()

            Swift.print(self.frame.width)

            return NSMakeSize(width, frame.size.height)
        }
    }

    // you need to invalidate the layout on text change, else it wouldn't grow by changing the text
    override func textDidChange(notification: NSNotification) {
        super.textDidChange(notification)
        self.invalidateIntrinsicContentSize()
    }
}
</code></pre>

<p>Essentially I just want the default behaviour of an HTML document like this:</p>

<pre><code>&lt;p id="dynamic"&gt;Hi&lt;/p&gt;

&lt;script&gt;
    document.getElementByID("dynamic").innerHtml = "Something really really really long"
&lt;/script&gt;
</code></pre>

<p>This is extremely painful for me as while I am new to Mac OS X and Cocoa, I am not a 'beginner' programmer.</p>

<p>In case it helps here is the contents of the attributes inspector. (it should just be all default values)</p>

<p><a href="https://i.stack.imgur.com/nKUwE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nKUwE.png" alt="attributes"></a></p>

<p><strong>Yes, auto layout is enabled</strong></p>

<p><a href="https://i.stack.imgur.com/JhyJn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JhyJn.png" alt="enabled"></a></p>