     }
     
     internal override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
-        let items = NSArray (array: super.layoutAttributesForElements(in: rect)!, copyItems: true)
+        let items = NSMutableArray (array: super.layoutAttributesForElements(in: rect)!, copyItems: true)
         
         items.enumerateObjects(using: { (object, index, stop) -> Void in
             let attributes = object as! UICollectionViewLayoutAttributes
             
             self.updateCellAttributes(attributes)
         })
+        
         return items as? [UICollectionViewLayoutAttributes]
     }
     

        let currentPage = (velocity.y < 0.0) ? floor(approximatePage) : ceil(approximatePage)
        
        // Create custom flickVelocity.
        let flickVelocity = velocity.y * 0.3
        
        // Check how many pages the user flicked, if <= 1 then flickedPages should return 0.
        let flickedPages = (abs(round(flickVelocity)) <= 1) ? 0 : round(flickVelocity)
        
        // Calculate newVerticalOffset.
        let newVerticalOffset = ((currentPage + flickedPages) * pageHeight) - self.collectionView!.contentInset.top

        return CGPoint(x: proposedContentOffset.x, y: newVerticalOffset)
    }
    
    internal override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {

        // make sure the zIndex of the next card is higher than the one we're swiping away.
        let nextIndexPath = IndexPath(row: itemIndexPath.row + 1, section: itemIndexPath.section)
        let nextAttr = self.layoutAttributesForItem(at: nextIndexPath)
        nextAttr?.zIndex = nextIndexPath.row

        // attributes for swiping card away
        let attr = self.layoutAttributesForItem(at: itemIndexPath)
        

        let finalY = max(minY, maxY)
        var origin = attributes.frame.origin
        let deltaY = (finalY - origin.y) / attributes.frame.height
        let translationScale = CGFloat((attributes.zIndex + 1) * 10)
        
        if let itemTransform = firstItemTransform {
            let scale = 1 - deltaY * itemTransform
            var t = CGAffineTransform.identity
            t = t.scaledBy(x: scale, y: 1)
            t = t.translatedBy(x: 0, y: (translationScale + deltaY * translationScale))
            
            attributes.transform = t
        }
        
        origin.x = (self.collectionView?.frame.width)! / 2 - attributes.frame.width / 2 - (self.collectionView?.contentInset.left)!
        origin.y = finalY
        attributes.frame = CGRect(origin: origin, size: attributes.frame.size)
        attributes.zIndex = attributes.indexPath.row
