                 attr.transform3D = CATransform3DMakeScale(1.0, 1.0, 1.0)
                 attr.zIndex = zIndex
                 zIndex += 1
-                attributes.append(attr)
+                attributes.updateValue(attr, forKey: indexPath)
                 
             }
         }


class AJMLayout: UICollectionViewLayout {
    
    private var attributes = [UICollectionViewLayoutAttributes]()
    private let itemSize : CGSize = CGSize(width: 300, height: 300)
    
    private var numberOfColumns = 6

    
    override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
        var layoutAttributes = [UICollectionViewLayoutAttributes]()
        for (_, value) in attributes {
            if value.frame.intersects(rect) {
                layoutAttributes.append(value)
            }
            
        }
        return layoutAttributes
    }
    
    override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
        if let value = attributes[indexPath as NSIndexPath] {
            return value
        }
        return UICollectionViewLayoutAttributes()
    }

