Skip to content

Instantly share code, notes, and snippets.

@danielt1263
Last active April 12, 2017 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielt1263/97f2413c7a3fc445e3c867d98842eaa5 to your computer and use it in GitHub Desktop.
Save danielt1263/97f2413c7a3fc445e3c867d98842eaa5 to your computer and use it in GitHub Desktop.
class ImagePickerDelegate: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate
{
let promise = Promise<UIImage>()
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = (info[UIImagePickerControllerEditedImage] as? UIImage) ?? (info[UIImagePickerControllerOriginalImage] as? UIImage) {
promise.fulfill(image)
}
else {
promise.reject(UIImagePickerControllerError.missingImage)
}
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
promise.reject(UserInteractionError.userCanceled)
}
}
enum UIImagePickerControllerError: Error {
case missingImage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment