0Pricing
Swift Academy · Lesson

UIViewControllerRepresentable

Embedding full UIKit view controllers like UIImagePickerController in SwiftUI.

What is UIViewControllerRepresentable?

Like UIViewRepresentable but wraps a full UIViewController for use inside SwiftUI.

struct ImagePickerView: UIViewControllerRepresentable {
  @Binding var image: UIImage?
}

makeUIViewController

Create and configure the UIKit view controller. Called once when SwiftUI first renders the representable.

func makeUIViewController(context: Context) -> UIImagePickerController {
  let vc = UIImagePickerController()
  vc.delegate = context.coordinator
  return vc
}

All lessons in this course

  1. UIViewRepresentable: Wrapping UIKit Views
  2. Coordinator Pattern for Delegate Communication
  3. UIViewControllerRepresentable
  4. UIHostingController: SwiftUI Inside UIKit
← Back to Swift Academy