     
     required public init(coder aDecoder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
+    }
+    
+    // MARK: - Cache management
+    private func photoAtIndexPath(indexPath: NSIndexPath) -> UIImage {
+        if (self.photosCache.objectAtIndex(indexPath.section).isKindOfClass(NSNull)) {
+
+            // get photo representation
+            let representation = self.photos[indexPath.section]
+            
+            // get image from library
+            let orientation = UIImageOrientation(representation.orientation())
+            let photo = UIImage(CGImage: representation.fullScreenImage().takeUnretainedValue(), scale: CGFloat(representation.scale()), orientation: orientation)
+
+            // save photo for later use
+            self.photosCache.replaceObjectAtIndex(indexPath.section, withObject: photo!)
+            
+            return photo!
+        } else {
+            return self.photosCache.objectAtIndex(indexPath.section) as UIImage
+        }
+    }
+    
+    public func photoURLsForSelectedImages() -> [NSURL] {
+        var selectedPhotos = [NSURL]()
+        for index in self.selectedPhotoIndices {
+            let photo = self.photoAtIndexPath(NSIndexPath(index: index))
+            let url = self.saveImageOnDisk(photo)
+            if ((url) != nil) {
+                selectedPhotos.append(url!)
+            }
+        }
+        
+        return selectedPhotos
+    }
+    
+    public func saveImageOnDisk(image: UIImage) -> NSURL? {
+        let nsDocumentDirectory = NSSearchPathDirectory.DocumentDirectory
+        let nsUserDomainMask = NSSearchPathDomainMask.UserDomainMask
+        if let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true) {
+            if paths.count > 0 {
+                if let dirPath = paths[0] as? String {
+                    let writePath = dirPath.stringByAppendingPathComponent(NSProcessInfo.processInfo().globallyUniqueString)
+                    UIImagePNGRepresentation(image).writeToFile(writePath, atomically: true)
+                    
+                    return NSURL(string: writePath)
+                }
+            }
+        }
+        return nil
     }
     
     // MARK: - UITableViewDataSource

            })
        }
        
        let library = ALAssetsLibrary()
        library.enumerateGroupsWithTypes((1 << 4), usingBlock: { (group: ALAssetsGroup!, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
            if group != nil {
                group.setAssetsFilter(ALAssetsFilter.allPhotos())
                group.enumerateAssetsUsingBlock({ (asset: ALAsset!, index: Int, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
                    if asset != nil {
                        let representation: ALAssetRepresentation = asset.defaultRepresentation()
                        let orientation = UIImageOrientation(representation.orientation())
                        let photo = UIImage(CGImage: representation.fullResolutionImage().takeUnretainedValue(), scale: CGFloat(representation.scale()), orientation: orientation)
                        self.photos.insert(photo!, atIndex: 0)
                    }
                })
                

    private let tableView = UITableView()
    private let collectionView: BRNImagePickerCollectionView
    
    private let library = ALAssetsLibrary()
    
    public var enlargedPreviews = false
    public var delegate: BRNImagePickerSheetDelegate?
    private var photos = [ALAssetRepresentation]()
    private var photosCache = NSMutableArray()
    private var selectedPhotoIndices = [Int]()
    private var previewsPhotos: Bool {
        return (self.photos.count > 0)
