title: UICollectionViewFlowLayout: collectionView!.contentSize vs collectionViewContentSize
body: <h3>Update</h3>
  <p>The issue seems to be resolved when using the designated <code>collectionViewContentSize()</code> method like so:</p>
  <pre><code>let contentSize = collectionViewContentSize()
  </code></pre>
  <p>Nevertheless, I would be very interested in an explanation behind this behaviour, so I've updated my question accordingly.</p>
  <h3>Original Question</h3>
  <p>I am trying to recreate the steps found in the first example of <a href="http://www.objc.io/issue-5/collection-views-and-uidynamics.html" rel="nofollow noreferrer">this article</a>, but using Swift and Storyboards.</p>
  <p>I have a custom <code>UICollectionViewFlowLayout</code> subclass with the following content:
  import UIKit</p>
  <pre><code>class SpringyFlowLayout: UICollectionViewFlowLayout {
      
      private lazy var animator: UIDynamicAnimator = {
          return UIDynamicAnimator(collectionViewLayout: self)
          }()
      
      override func prepareLayout() {
          super.prepareLayout()
          
          let contentSize = collectionView!.contentSize
          let items = super.layoutAttributesForElementsInRect(CGRect(origin: CGPointZero, size: contentSize)) as! [UICollectionViewLayoutAttributes]
          
          if animator.behaviors.isEmpty {
              for item in items {
                  let spring = UIAttachmentBehavior(item: item, attachedToAnchor: item.center)
                  spring.length = 0
                  spring.damping = 0.8
                  spring.frequency = 1.0
                  animator.addBehavior(spring)
              }
          }
      }
      
      override func layoutAttributesForElementsInRect(rect: CGRect) -&gt; [AnyObject]? {
          return animator.itemsInRect(rect)
      }
      
      
      override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -&gt; UICollectionViewLayoutAttributes! {
          return animator.layoutAttributesForCellAtIndexPath(indexPath)
      }
      
      override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -&gt; Bool {
          let delta = newBounds.origin.y - collectionView!.bounds.origin.y
          for spring in animator.behaviors {
              let items = spring.items as! [UICollectionViewLayoutAttributes]
              if let attributes = items.first {
                  attributes.center.y += delta
                  animator.updateItemUsingCurrentState(attributes)
              }
          }
          return false
      }
  </code></pre>
  <p>I have the correct Layout class set in Storyboards. When I run the app, my Collection View is empty.</p>
  <p>I have determined that the issue is in the following snipped:</p>
  <pre><code>override func prepareLayout() {
          super.prepareLayout()
          
          let contentSize = collectionView!.contentSize
          let items = super.layoutAttributesForElementsInRect(CGRect(origin: CGPointZero, size: contentSize)) as! [UICollectionViewLayoutAttributes]
  //...
  }
  </code></pre>
  <p>Since I subclass <code>UICollectionViewFlowLayout</code>, I thought I can rely on the super implementation to lay out the elements for me, and then modify their attributes. But when I check contentSize, it reports the width correctly, but the height is 0.</p>
  <p>This leads to an empty items array -&gt; no behaviors in <code>animator</code> -&gt; <code>animator.itemsInRect(_)</code> returning an empty array -&gt; the empty Collection View.</p>
  <p>I just can't seem to find out what I'm missing. There should be no need to override the  <code>contentSize()</code> method, since I'm using a flow layout.</p>