Last active
June 15, 2016 09:38
-
-
Save zhxnlai/3b6519cfeab1e24f4263e8b6586295d8 to your computer and use it in GitHub Desktop.
Async Task Extending View Controller
This file contains 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 ImagePickerDemoViewController: UIViewController { | |
let imageView = UIImageView() | |
func launchImagePicker() { | |
Task { | |
do { | |
let data = try ImagePickerTask(viewController: self).await() | |
} catch Error.PhotoLibraryNotAvailable { | |
alert("Photo Library is Not Available") | |
} | |
guard let image = data?[UIImagePickerControllerOriginalImage] as? UIImage else { | |
self.imageView.image = nil | |
return | |
} | |
self.imageView.image = image | |
}.async() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment