© Bear Cahill 2021
B. CahillUI Design for iOS App Developmenthttps://doi.org/10.1007/978-1-4842-6449-2_14

14. SwiftUI in UIKit

Bear Cahill1  
(1)
Denton, TX, USA
 

We looked at how to use existing UIKit views in SwiftUI. Now we’ll look at how to use SwiftUI in UIKit.

You may have an existing project that you want to add new UI using SwiftUI. So you have your Storyboard setup for all your interface and navigation. It’s actually pretty easy to add SwiftUI views to your project.

When we incorporated a UIView in our app, we used UIViewRepresentable. That protocol facilitated creating our UIView instances.

UIKit provides a mechanism for doing it the other way around. There’s a UIViewController subclass called UIHostingController. Similarly, for macOS development, ...

Get UI Design for iOS App Development: Using 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.