 }
 
 
+// internal scope because used by ALAssetsLibrary extension
+@objc class UIImagePickerControllerInfoProxy: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
+    let (promise, fulfill, reject) = Promise<[String : AnyObject]>.pendingPromise()
+    var retainCycle: AnyObject?
+  
+    required override init() {
+        super.init()
+        retainCycle = self
+    }
+  
+    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
+        fulfill(info)
+        retainCycle = nil
+    }
+  
+    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
+        reject(UIImagePickerController.Error.Cancelled)
+        retainCycle = nil
+    }
+}
+
+
 extension UIImagePickerController {
     public enum Error: CancellableErrorType {
         case Cancelled

            return Promise(error: Error.NavigationControllerEmpty)
        }
    }

    public func promiseViewController(vc: UIImagePickerController, animated: Bool = true, completion: (() -> Void)? = nil) -> Promise<UIImage> {
        let proxy = UIImagePickerControllerProxy()
        vc.delegate = proxy

            }
            throw Error.NoImageFound
        }.always {
            self.dismissViewControllerAnimated(animated, completion: nil)
        }
    }

    public func promiseViewController(vc: UIImagePickerController, animated: Bool = true, completion: (() -> Void)? = nil) -> Promise<[String: AnyObject]> {
        let proxy = UIImagePickerControllerInfoProxy()
        vc.delegate = proxy
        presentViewController(vc, animated: animated, completion: completion)
        return proxy.promise.always {
            self.dismissViewControllerAnimated(animated, completion: nil)
        }
    }
