title: How to set up an NSTextView programmatically with explicit NSLayoutManager, NSTextStorage, NSTextContainer?
body: <p>Following the apple documentation I am trying to set up a simple <code>NSTextView</code> via its two constructor methods. </p>
  
  <p>I am placing the below code inside the <code>viewDidAppear</code> method of the view controller of the content view. textView is an instance of <code>NSTextView</code>, frameRect is the frame of the content view.</p>
  
  <p>The following Swift code works (gives me an editable textView with the text showing on the screen):</p>
  
  <pre><code>    textView = NSTextView(frame: frameRect!)
      self.view.addSubview(textView)
      textView.textStorage?.appendAttributedString(NSAttributedString(string: "Hello"))
  </code></pre>
  
  <p>The following does NOT work (text view is not editable and no text shown on the screen):</p>
  
  <pre><code>    var textStorage = NSTextStorage()
      var layoutManager = NSLayoutManager()
      textStorage.addLayoutManager(layoutManager)
      var textContainer = NSTextContainer(containerSize: frameRect!.size)
      layoutManager.addTextContainer(textContainer)
      textView = NSTextView(frame: frameRect!, textContainer: textContainer)
  
      textView.editable = true
      textView.selectable = true
      self.view.addSubview(textView)
  
      textView.textStorage?.appendAttributedString(NSAttributedString(string: "Hello more complex"))
  </code></pre>
  
  <p><strong>What am I doing wrong in the second example</strong>? I am trying to follow the example given in Apple's "Cocoa Text Architecture Guide" where they discuss setting up an <code>NSTextView</code> by explicitly instantiating its web of helper objects.</p>