         super.init()
     }
     
+    deinit {
+//        photosManager.stopCachingImagesForAllAssets()
+    }
+    
     func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return assets.count
+        if let assets = assets {
+            return assets.count
+        }
+        
+        return 0
     }
     
     func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

            NSSortDescriptor(key: "creationDate", ascending: false)
        ]
        
        if let results = PHAsset.fetchAssetsWithMediaType(.Image, options: fetchOptions) {
            var assets: [PHAsset] = []
            results.enumerateObjectsUsingBlock { (object, idx, _) in
                if let asset = object as? PHAsset {
                    assets.append(asset)
                }
            }
            

import Photos

internal class PhotosDataSource : NSObject, UICollectionViewDataSource {
    internal var imageSize: CGSize = CGSize(width: 0, height: 0) {
        willSet {
            if CGSizeEqualToSize(newValue, imageSize) == false {
                stopCaching()
            }
        }
        didSet {
            if CGSizeEqualToSize(oldValue, imageSize) == false {
                startCaching()
            }
        }
    }
    
    private let photoCellIdentifier = "photoCellIdentifier"
    private let photosManager = PHCachingImageManager()
    private let imageContentMode: PHImageContentMode = .AspectFill
    private var assets: [PHAsset]? {
        willSet {
            stopCaching()
        }
        didSet {
            startCaching()
        }
    }
    
    override init() {
