Skip to content

Instantly share code, notes, and snippets.

@zhxnlai
Last active June 15, 2016 09:38
Show Gist options
  • Save zhxnlai/3b6519cfeab1e24f4263e8b6586295d8 to your computer and use it in GitHub Desktop.
Save zhxnlai/3b6519cfeab1e24f4263e8b6586295d8 to your computer and use it in GitHub Desktop.
Async Task Extending View Controller
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