Last active
September 2, 2018 15:58
-
-
Save laevandus/1f924b75880569c7009bdb77ba49f5f8 to your computer and use it in GitHub Desktop.
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
@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