Implementing UIViewControllerRepresentable

Let's start by heading on over and taking a look at our implementation of ImageHelper.swift. Much like UIViewRepresentable, the layout and required functions are pretty much the same. So, for this reason, we won't go through and create another UIViewControllerRepresentable struct; instead, we'll just cover how we created ImagePickerViewController function by function.

First of all, let's take a look at our makeUIViewController() function. Much like the makeUIView() function, here, we create an instance of UIViewController we want to use and return this to SwiftUI so that it can use it:

func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePickerViewController>) -> UIImagePickerController ...

Get Learn SwiftUI 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.