Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
@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