0Pricing
Swift Academy · Lesson

Coordinator Pattern for Delegate Communication

Using makeCoordinator() to relay UIKit delegate callbacks into SwiftUI.

Why Coordinators?

UIKit delegates require an object reference. SwiftUI's value types can't be delegates. The Coordinator is the bridge.

struct ImagePicker: UIViewControllerRepresentable {
  @Binding var image: UIImage?
  // Coordinator will be the UIImagePickerControllerDelegate
}

makeCoordinator()

Implement makeCoordinator() returning a Coordinator instance. SwiftUI calls this before makeUIView/Controller.

func makeCoordinator() -> Coordinator {
  Coordinator(self)
}

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