Let's step through what we've just done. We'll begin at IBAction and have a look at the UIPickerView view we've created:
let picker = UIImagePickerController() // 1
picker.delegate = self // 2
picker.allowsEditing = false // 3
picker.sourceType = UIImagePickerController.isSourceTypeAvailable
(.camera) ? .camera : .photoLibrary // 4
present(picker, animated: true) // 5
Let's go through this one line at a time:
- We instantiate an instance of UIImagePickerController – an available API that will allow us to choose an image based on a specific source.
- We set the delegate as self, so we can harness any results or actions caused by UIImagePickerController.
- We set allowEditing to false, which is used to hide controls when the camera is our source.
- In this instance, we set the source type based on whether the camera is available or not (so it works well with the simulator).
- Finally, we present our view controller.
Now, let&apos...