Skip to content

Instantly share code, notes, and snippets.

@Marchuck
Last active January 10, 2019 12:27
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 Marchuck/7ef3163c68365cd0d0008ebcab1bc769 to your computer and use it in GitHub Desktop.
Save Marchuck/7ef3163c68365cd0d0008ebcab1bc769 to your computer and use it in GitHub Desktop.
protocol ImageDelegate{
func onImageReceived(_ picker: ImagePickerController, didReceiveValue value: UIImage)
func onCancel(_ picker: ImagePickerController)
}
class TakePictureController : UIViewController, ImageDelegate{
func takePicture(){
let imagePicker = ImagePickerController()
imagePicker.delegate = self//self conforms to ImageDelegate protocol
//...other setup
present(imagePicker, animated: true, completion: nil)
}
func onImageReceived(_ picker: ImagePickerController, didReceiveValue value: UIImage){
imageView.image = value
picker.dismiss()
}
func onCancel(_ picker: ImagePickerController){
picker.dismiss()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment