Using the UIImagePickerController is pretty straightforward. The problem starts, when you have multiple controllers, and you need the picking ability in both of them. You can make a parent class with the core functionality, but that's old-school for a Swift developer, isn't it?

The final product

I imagine my protocol oriented image picker api something like this.

The problem

TL;DR: @objc functions may not currently be in protocol extensions. You could create a base class instead, though that's not an ideal solution.

source: StackOverflow

The main idea is to have a protocol, that implements the UIImagePickerController-Delegate. This would be an easy thing, but the image picker protocol is an ancient one from the Objective-C times, so the system will never call your delegate methods if you do this. That's why we need a little trick, so we are going to use a helper class, but first, let's define our main protocol.

Next, we create a default implementation for the showImagePicker method, if our class is kind of a UIViewController. The helper class is going to be our delegate, so that instance will take care of the photo selection.

As I mentioned before, we need a helper class. I really don't like singletons, but for this purpose one will do. It's going to be completely private, so no-one else can access it. After the photo is selected, you won't need this class in memory that's why I made a dispose method to clean it up after the job.

Finally, we implement the UIImagePickerControllerDelegate methods, and tell the helper class to call back our protocol implementation with the final image data.

Yeah, almost forgot this... stupid thing, but we need this implementation as well.

From now on if your view controller conforms to the ImagePickerRepresentable protocol, you can pick images with just a few lines of code. I wanted to find an universal solution for this problem, but unfortunately the frameworks provided by Apple are not 100% Swift-ified, so I needed the singleton hack. I really hope that in the future we can just extend the UIImagePickerControllerDelegate protocol, and eliminate the need of this trick.