Taking Pictures and UIImagePickerController

In the takePicture(_:) method, you will instantiate a UIImagePickerController and present it on the screen. When creating an instance of UIImagePickerController, you must set its sourceType property and assign it a delegate. Because there is set-up work needed for the image picker controller, you need to create and present it programmatically instead of through the storyboard.

Setting the image picker’s sourceType

The sourceType constant tells the image picker where to get images. It has three possible values:

UIImagePickerControllerSourceType.camera

Allows the user to take a new photo.

UIImagePickerControllerSourceType.photoLibrary

Prompts the user to select an album ...

Get iOS Programming: The Big Nerd Ranch Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.