UIHostingController
A UIKit view controller that manages a SwiftUI view hierarchy.
Declaration
@MainActor @preconcurrency class UIHostingController<Content> where Content : ViewOverview
Create a UIHostingController object when you want to integrate SwiftUI views into a UIKit view hierarchy. At creation time, specify the SwiftUI view you want to use as the root view for this view controller; you can change that view later using the rootView property. Use the hosting controller like you would any other view controller, by presenting it or embedding it as a child view controller in your interface.
Topics
Creating a hosting controller object
Responding to view-related events
loadView()viewWillAppear(_:)viewDidAppear(_:)viewWillDisappear(_:)viewDidDisappear(_:)willMove(toParent:)didMove(toParent:)viewWillTransition(to:with:)viewWillLayoutSubviews()target(forAction:withSender:)rootView
Checking for modality
Managing the size
sizingOptionspreferredContentSizeDidChange(forChildContentContainer:)sizeThatFits(in:)safeAreaRegions
Configuring the status bar
preferredStatusBarStylepreferredStatusBarUpdateAnimationprefersStatusBarHiddenchildForStatusBarStylechildForStatusBarHidden
Configuring the home indicator
Configuring the interface appearance
preferredUserInterfaceStylepreferredScreenEdgesDeferringSystemGestureschildForScreenEdgesDeferringSystemGestures