title: How to add an UICollectionViewLayout programmatically?
body: <p>I'm trying to setup a <code>UICollectionViewLayout</code> programmatically. I'm using a <code>UICollectionView</code> also without using storyboards, as well as settings its constraints.</p>
  
  <p>I've followed <a href="https://www.raywenderlich.com/107439/uicollectionview-custom-layout-tutorial-pinterest" rel="nofollow noreferrer">Ray Wenderlich</a> tutorial on the subject with some changes to adapt the code to Swift 3 (as AZCoder2 did <a href="https://github.com/AZCoder2/Pinterest" rel="nofollow noreferrer"><a href="https://github.com/AZCoder2/Pinterest" rel="nofollow noreferrer">https://github.com/AZCoder2/Pinterest</a></a>).</p>
  
  <p>Since all these examples uses storyboards, I've also introduced some changes to create the <code>UICollectionView</code> and its <code>UICollectionViewLayout</code>:</p>
  
  <pre><code>collectionViewLayout = PinterestLayout()
  collectionViewLayout.delegate = self
  collectionView = UICollectionView.init(frame: .zero, collectionViewLayout: collectionViewLayout)
  </code></pre>
  
  <p>The result: I can't see anything. If I change the <code>UICollectionViewLayout</code> with the one that Apple provides (<code>UICollectionViewFlowLayout</code>), at least I can see the cells with their content. If I implement some changes and use the storyboard, everything works great but it's not the way I want to accomplish this. The whole view is made programmatically and the collection view is a part of it. </p>
  
  <p>What am I missing? Is it something to do with the way I instantiate the <code>UICollectionViewLayout</code>? Do I have to register something (for example, as I need to register the reusable cell)?</p>