Generic Class

UIHostingController

A UIKit view controller that manages a SwiftUI view hierarchy.

Declaration

class UIHostingController<Content> : UIViewController where Content : View

Overview

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

init(rootView: Content)

Creates a hosting controller object that wraps the specified SwiftUI view.

init?(coder: NSCoder, rootView: Content)

Creates a hosting controller object from an archive and the specified SwiftUI view.

init(nibName: String?, bundle: Bundle?)

Creates a hosting controller object from the contents of the specified nib file.

init?(coder: NSCoder)

Creates a hosting controller object from the contents of the specified archive.

Getting the Root View

var rootView: Content

The root view of the SwiftUI view hierarchy managed by this view controller.

Configuring the Interface Appearance

func sizeThatFits(in: CGSize) -> CGSize

Calculates and returns the most appropriate size for the current view.

var preferredStatusBarStyle: UIStatusBarStyle

The preferred status bar style for the view controller.

var preferredStatusBarUpdateAnimation: UIStatusBarAnimation

The animation style to use when hiding or showing the status bar for this view controller.

var preferredUserInterfaceStyle: UIUserInterfaceStyle

The preferred interface style for this view controller.

var prefersStatusBarHidden: Bool

A Boolean value that indicates whether the view controller prefers the status bar to be hidden or shown.

func contains(UIFocusEnvironment) -> Bool

Returns a Boolean value that indicates whether the view controller contains the specified focus environment.

Comparing View Controllers

static func == (NSObject, NSObject) -> Bool

Returns a Boolean value indicating whether two values are equal.

static func != (UIHostingController<Content>, UIHostingController<Content>) -> Bool

Returns a Boolean value indicating whether the two objects are not equivalent.

Getting Hash Information

var hashValue: Int

The hash value.

func hash(into: inout Hasher)

Hashes the essential components of this value by feeding them into the given hasher.

See Also

UIKit Hosting

protocol UIViewControllerRepresentable

A view that represents a UIKit view controller.

protocol UIViewRepresentable

A wrapper for a UIKit view that you use to integrate that view into your SwiftUI view hierarchy.