NSCollectionView dataSource not working properly
<p>I'm experimenting with the new <code>NSCollectionView</code> API, introduced in El Capitan.</p>

<p>Following the WWDC video, I create a subclass of <code>NSCollectionViewFlowLayout</code> to determine the layout of the collection view. </p>

<pre><code>class Layout : NSCollectionViewFlowLayout {

  override func prepareLayout() {

    super.prepareLayout()

    self.minimumInteritemSpacing = 0
    self.minimumLineSpacing = 0

    let cheight = self.collectionView!.bounds.height
    let cwidth = self.collectionView!.bounds.width

    self.itemSize = CGSizeMake(cwidth / 2.0, cheight / 6.0)

  }

}
</code></pre>

<p>After that, I've created a <code>NSObject</code> subclass to serve as data source.</p>

<pre><code>class DataSource : NSObject, NSCollectionViewDataSource {

  func collectionView(collectionView: NSCollectionView, numberOfItemsInSection section: Int) -&gt; Int {
    return 5
  }

  func collectionView(collectionView: NSCollectionView, itemForRepresentedObjectAtIndexPath indexPath: NSIndexPath) -&gt; NSCollectionViewItem {

    /* DOESN'T GET CALLED! */

    let item = collectionView.makeItemWithIdentifier("cell", forIndexPath: indexPath)

    item.view.wantsLayer = true
    item.view.layer?.backgroundColor = NSColor.redColor().CGColor

    return item

  }

}
</code></pre>

<p>The <strong>issue</strong> is that <code>collectionView:itemForRepresentedObjectAtIndexPath:</code> never gets called.</p>

<p>This is how I initialise the collection view:</p>

<pre><code>let collectionView = NSCollectionView(frame: view.bounds)

let dataSource = DataSource()
let layout = Layout()

collectionView.collectionViewLayout = layout
collectionView.registerClass(NSCollectionViewItem.self,     
                             forItemWithIdentifier: "cell")
collectionView.dataSource = dataSource

collectionView.backgroundColors = [.blackColor()]
</code></pre>

<p>I can clearly see the collection view in its superview, but there are no cells.</p>

<p>Also, this line, if called outside the delegate (but after the cell class is registered) makes the app crash!</p>

<pre><code>let item = collectionView.makeItemWithIdentifier("cell", forIndexPath: /*any index path*/)
</code></pre>

<p>Am I doing something wrong or is <code>NSCollectionView</code> new API broken?</p>

<p>Thanks.</p>