34. Integrating SwiftUI with UIKit
Apps developed before the introduction of SwiftUI will have been developed using UIKit and other UIKit-based frameworks included with the iOS SDK. Given the benefits of using SwiftUI for future development, it will be a common requirement to integrate the new SwiftUI app functionality with the existing project code base. Fortunately, this integration can be achieved with relative ease using the UIHostingController.
34.1 An Overview of the Hosting Controller
The hosting controller (in the form of the UIHostingController class) is a subclass of UIViewController, the sole purpose of which is to enclose a SwiftUI view so that it can be integrated into an existing UIKit-based project.
Using a hosting view controller, a SwiftUI view can be treated as an entire scene (occupying the full screen) or treated as an individual component within an existing UIKit scene layout by embedding a hosting controller in a container view. A container view essentially allows...