title: How to have a NSCollectionView item have dynamic height based on text field
body: <p>I have a NSCollectionView which presents items in a list.</p>
  
  <p><a href="https://i.stack.imgur.com/e59Ih.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e59Ih.png" alt="enter image description here"></a></p>
  
  <p>my layout is defined by</p>
  
  <pre><code>private func configureCollectionView() {
      let flowLayout = NSCollectionViewFlowLayout()
  
      flowLayout.itemSize.width = self.view.frame.width
      //flowLayout.itemSize.height = 50
      flowLayout.minimumLineSpacing = 8
      myCollectionView.collectionViewLayout = flowLayout
      view.wantsLayer = true
  }
  </code></pre>
  
  <p>When a long peice of text is entered as an item, I am trying to get the item height for that 'cell' to grow/expand with the content of the text.
  I have setup my contsraints using AutoLayout and I fairly certain that it is setup correctly for this, but my item height remains fixed at 50 (I can't tell where this is getting set).</p>
  
  <p>I am trying to take advantage of </p>
  
  <pre><code>func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; NSSize 
  </code></pre>
  
  <p>But I'm not having much luck with this either as I don't know how to best figure out what the Size should be (the height in this case)</p>
  
  <p>Any suggestions on this problem?</p>
  
  <p>Thanks!</p>