Created
April 13, 2017 14:00
-
-
Save danielt1263/a317719e374e9147f32afd7f0f9b0ace to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController | |
{ | |
@IBOutlet weak var avatarView: UIImageView! | |
var api: API! | |
@IBAction func changeAvatar(_ sender: UITapGestureRecognizer) { | |
guard let senderView = sender.view else { fatalError("Tapped on viewless gesture recognizer?") } | |
getImage(focusView: senderView).then { image -> Promise<UIImage> in | |
guard let data = UIImageJPEGRepresentation(image, 0.8) else { throw JPEGRepresentationError.badImage } | |
return self.api.upload(avatar: data).then { image } | |
} | |
.then { image in | |
self.avatarView.image = image | |
} | |
.catch { error in | |
guard error as? UserInteractionError != .userCanceled else { return } | |
self.displayInformationAlert(title: "Error", message: error.localizedDescription) | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment