Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active September 2, 2018 15:58
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 laevandus/1f924b75880569c7009bdb77ba49f5f8 to your computer and use it in GitHub Desktop.
Save laevandus/1f924b75880569c7009bdb77ba49f5f8 to your computer and use it in GitHub Desktop.
@IBAction func takePhoto(_ sender: Any) {
openPhotoPicker(withSource: .camera)
}
@IBAction func choosePhoto(_ sender: Any) {
openPhotoPicker(withSource: .photoLibrary)
}
@discardableResult private func openPhotoPicker(withSource source: UIImagePickerController.SourceType) -> Bool {
guard UIImagePickerController.isSourceTypeAvailable(source) else { return false }
let picker: UIImagePickerController = {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = source
return picker
}()
present(picker, animated: true, completion:nil)
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment