title: What replacement for UITableViewAutomaticDimension should I use to get the same effect in NSTableView?
body: <p>In iOS projects I do something like that:</p>
  
  <pre><code>tableView.rowHeight = UITableViewAutomaticDimension
  tableView.estimatedRowHeight = 30
  </code></pre>
  
  <p>and have nicely resizing cells.</p>
  
  <p>What should I do to reproduce the same behaviour in macOS project?</p>
  
  <hr>
  
  <p>Ok, <code>func tableView(_ tableView: NSTableView, heightOfRow row: Int) -&gt; CGFloat</code>. </p>
  
  <p>Should I configure my SubView (cell view) (that actually is NSView) twice...</p>
  
  <p>In both methods - <code>heightOfRow</code> and <code>viewFor tableColumn</code>?</p>
  
  <p>I heard about reusing of cells, but can it be done without nibs?</p>
  
  <p>Anyway, if I doing so I get not quite the intended result.</p>
  
  <p>Delegate/Datasource:</p>
  
  <pre><code>let items = ["second label",
               "second label with alotoftext alotof...", // long line
               "second label"]
  
  func numberOfRows(in tableView: NSTableView) -&gt; Int {
      return 3
  }
  
  func tableView(_ tableView: NSTableView, heightOfRow row: Int) -&gt; CGFloat {
      let cell = SubView(text: items[row])
      cell.layoutSubtreeIfNeeded()
      return cell.frame.size.height
  }
  
  func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -&gt; NSView? {
      return SubView(text: items[row])
  }
  </code></pre>
  
  <p>SubView:</p>
  
  <pre><code>init(text: String) {
      super.init(frame: CGRect.zero)
  
      let text1 = NSTextField(labelWithString: "first label")
      let text2 = NSTextField(labelWithString: text)
  
      text2.lineBreakMode = .byWordWrapping
      text2.setContentCompressionResistancePriority(100, for: .horizontal)
  
      self.addSubview(text1)
      self.addSubview(text2)
  
      text1 &lt;- [Top(5), Left(5), Right(5)]
      text2 &lt;- [Top(0).to(text1, .bottom), Left(5), Right(5), Bottom(5)]
  
  }
  </code></pre>
  
  <p>Last two lines are <a href="https://github.com/nakiostudio/EasyPeasy" rel="nofollow noreferrer">EasyPeasy</a> constraints.</p>
  
  <p>So, result is: <a href="https://i.stack.imgur.com/QgAFU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QgAFUm.png" alt="wrong"></a></p>
  
  <p>Where is my mistake?</p>
  
  <hr>
  
  <p>And just one more question: what should I do to make cells grow/decrease vertically to fit all subviews inside of them accordingly to resizing width of tableView?</p>
  
  <p>Oh, seem to have realized.</p>
  
  <p>Just added the observer:</p>
  
  <pre><code>name: NSNotification.Name.NSViewFrameDidChange,
  object: self.scrollView
  </code></pre>
  
  <p>And </p>
  
  <pre><code>let vr = scrollView.contentView.visibleRect
  let indexes = tableView.rows(in: vr).toRange()!
  tableView.noteHeightOfRows(withIndexesChanged: IndexSet(integersIn: indexes))
  </code></pre>
  
  <p>in selector method. </p>
  
  <hr>
  
  <p>Yep. The same view (SubView) works perfect without tableView.
  <a href="https://i.stack.imgur.com/RDyzSl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RDyzSl.png" alt=""></a> <a href="https://i.stack.imgur.com/oEBmKm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oEBmKm.png" alt=""></a></p>
  
  <p>But I still have the above-described problem with wrong-sized cellViews.</p>
  
  <p>P.S.: Sorry for my english, I hope everything is clear.</p>