     }
 
     override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
-        var result = [UICollectionViewLayoutAttributes]()
-        for (_, attributes) in self.cachedAttributes {
-            if CGRectIntersectsRect(attributes.frame, rect) {
-                result.append(attributes)
-            }
+        return self.cachedAttributes.map({ (_, attributes) -> UICollectionViewLayoutAttributes in
+            return attributes
+        }).filter { attributes -> Bool in
+            return CGRectIntersectsRect(attributes.frame, rect)
         }
-        return result
     }
 
     override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {

        if self.indexPathsToAnimate.indexOf(itemIndexPath) == nil {
            return super.initialLayoutAttributesForAppearingItemAtIndexPath(itemIndexPath)
        }
        var offset = self.collectionViewContentSize().height + 300 * CGFloat(itemIndexPath.section) * CGFloat((self.collectionView!.numberOfItemsInSection(itemIndexPath.section)))
        if itemIndexPath.row == 0 {
            offset += 300
        } else if itemIndexPath.row == 2 {
            offset += 600
        }
        var delay = 0.1 * Double(itemIndexPath.section) * Double((self.collectionView!.numberOfItemsInSection(itemIndexPath.section)))
        if itemIndexPath.row == 0 {
            delay += 0.1
        } else if itemIndexPath.row == 2 {
            delay += 0.1 * 2
        }

        let transformAnimation = CABasicAnimation(keyPath: "center.y")
        transformAnimation.duration = 3
        transformAnimation.fromValue = offset + self.cachedAttributes[itemIndexPath]!.center.y
        transformAnimation.toValue = self.cachedAttributes[itemIndexPath]!.center.y
        transformAnimation.timingFunction = CAMediaTimingFunction(controlPoints: 0.45, 1.2, 0.75, 1.0)
        transformAnimation.removedOnCompletion = false
        transformAnimation.fillMode = kCAFillModeForwards
        transformAnimation.beginTime = CACurrentMediaTime() + delay

        let attributes = MSTumblrMenuLayoutAttributes(forCellWithIndexPath: itemIndexPath)
        attributes.alpha = 1.0
        attributes.animation = transformAnimation
        attributes.size = self.cellSize
        attributes.center = CGPointMake(self.cachedAttributes[itemIndexPath]!.center.x,  offset + self.cachedAttributes[itemIndexPath]!.center.y)
        return attributes


    var cellSize = CGSizeMake(100, 120)
    let cellSpace: CGFloat = 20.0
    let rowsCount = 3
    private var indexPathsToAnimate : Array<NSIndexPath>!
    var cachedAttributes = [NSIndexPath: MSTumblrMenuLayoutAttributes]()

