Integrating UIKit & SwiftUI

Learn how to integrate SwiftUI views into your UIKit apps and view hierarchies, and how to host UIKit views and view controllers in SwiftUI. Coordinate data flow from SwiftUI to UIKit and back again! By Catie Catterwaul.

Leave a rating/review
Download materials
Save for later
Comments
Share

Learning path

This is part of the iOS User Interfaces with UIKit learning path. View path.

Who is this for?

This course finishes up our iOS User Interfaces with UIKit learning path. It is intended for developers with some experience building iOS apps with UIKit and SwiftUI, as you'll be using both in every episode.

Covered concepts

  • UIHostingController
  • IBSegueAction
  • UIViewRepresentable
  • UIViewControllerRepresentable
  • SwiftUI Coordinator

Part 1: Part 1

An easy way to start using SwiftUI is to add some to your existing UIKit apps! Replace a UIViewController with a SwiftUI view in the storyboard, and manage data flow between SwiftUI and the rest of the app.

Toggle description

You don't have to replace entire view controllers to get started with SwiftUI. You can embed SwiftUI views right into your view hierarchy from the storyboard with the help of @IBSegueAction.

Toggle description

If UIKit has a view or control that you need in your SwiftUI app, you can integrate it with UIViewRepresentable.

Toggle description

SwiftUI doesn't have a native photo picker, so you'll need UIKit's help to pick photos from your app. Learn how to use the new PHPicker in your SwiftUI apps.

SwiftUI doesn't make much use of the delegate pattern, but it's required for many UIKit controls like the PHPicker. Use a coordinator to add the delegates you need to host UIKit views.

Toggle description

The coordinator can help you out with more than delegates! You can also use it to implement target action for UIKit controls in SwiftUI.