<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/UIHostingController",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI19UIHostingControllerC"
  },
  "title" : "UIHostingController"
}
-->

# UIHostingController

A UIKit view controller that manages a SwiftUI view hierarchy.

```
@MainActor @preconcurrency class UIHostingController<Content> 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`](/documentation/SwiftUI/UIHostingController/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)`](/documentation/SwiftUI/UIHostingController/init(rootView:))

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

[`init?(coder: NSCoder, rootView: Content)`](/documentation/SwiftUI/UIHostingController/init(coder:rootView:))

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

[`init?(coder: NSCoder)`](/documentation/SwiftUI/UIHostingController/init(coder:))

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

### Responding to view-related events

[`func loadView()`](/documentation/SwiftUI/UIHostingController/loadView())

[`func viewWillAppear(Bool)`](/documentation/SwiftUI/UIHostingController/viewWillAppear(_:))

Notifies the view controller that its view is about to be added to a
view hierarchy.

[`func viewDidAppear(Bool)`](/documentation/SwiftUI/UIHostingController/viewDidAppear(_:))

Notifies the view controller that its view has been added to a
view hierarchy.

[`func viewWillDisappear(Bool)`](/documentation/SwiftUI/UIHostingController/viewWillDisappear(_:))

Notifies the view controller that its view will be removed from a
view hierarchy.

[`func viewDidDisappear(Bool)`](/documentation/SwiftUI/UIHostingController/viewDidDisappear(_:))

[`func willMove(toParent: UIViewController?)`](/documentation/SwiftUI/UIHostingController/willMove(toParent:))

[`func didMove(toParent: UIViewController?)`](/documentation/SwiftUI/UIHostingController/didMove(toParent:))

[`func viewWillTransition(to: CGSize, with: any UIViewControllerTransitionCoordinator)`](/documentation/SwiftUI/UIHostingController/viewWillTransition(to:with:))

[`func viewWillLayoutSubviews()`](/documentation/SwiftUI/UIHostingController/viewWillLayoutSubviews())

[`func target(forAction: Selector, withSender: Any?) -> Any?`](/documentation/SwiftUI/UIHostingController/target(forAction:withSender:))

[`var rootView: Content`](/documentation/SwiftUI/UIHostingController/rootView)

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

### Checking for modality

[`var isModalInPresentation: Bool`](/documentation/SwiftUI/UIHostingController/isModalInPresentation)

### Managing the size

[`var sizingOptions: UIHostingControllerSizingOptions`](/documentation/SwiftUI/UIHostingController/sizingOptions)

The options for how the hosting controller tracks changes to the size
of its SwiftUI content.

[`func preferredContentSizeDidChange(forChildContentContainer: any UIContentContainer)`](/documentation/SwiftUI/UIHostingController/preferredContentSizeDidChange(forChildContentContainer:))

[`func sizeThatFits(in: CGSize) -> CGSize`](/documentation/SwiftUI/UIHostingController/sizeThatFits(in:))

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

[`var safeAreaRegions: SafeAreaRegions`](/documentation/SwiftUI/UIHostingController/safeAreaRegions)

The safe area regions that this view controller adds to its view.

### Configuring the status bar

[`var preferredStatusBarStyle: UIStatusBarStyle`](/documentation/SwiftUI/UIHostingController/preferredStatusBarStyle)

The preferred status bar style for the view controller.

[`var preferredStatusBarUpdateAnimation: UIStatusBarAnimation`](/documentation/SwiftUI/UIHostingController/preferredStatusBarUpdateAnimation)

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

[`var prefersStatusBarHidden: Bool`](/documentation/SwiftUI/UIHostingController/prefersStatusBarHidden)

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

[`var childForStatusBarStyle: UIViewController?`](/documentation/SwiftUI/UIHostingController/childForStatusBarStyle)

[`var childForStatusBarHidden: UIViewController?`](/documentation/SwiftUI/UIHostingController/childForStatusBarHidden)

### Configuring the home indicator

[`var prefersHomeIndicatorAutoHidden: Bool`](/documentation/SwiftUI/UIHostingController/prefersHomeIndicatorAutoHidden)

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

[`var childForHomeIndicatorAutoHidden: UIViewController?`](/documentation/SwiftUI/UIHostingController/childForHomeIndicatorAutoHidden)

### Configuring the interface appearance

[`var preferredUserInterfaceStyle: UIUserInterfaceStyle`](/documentation/SwiftUI/UIHostingController/preferredUserInterfaceStyle)

The preferred interface style for this view controller.

[`var preferredScreenEdgesDeferringSystemGestures: UIRectEdge`](/documentation/SwiftUI/UIHostingController/preferredScreenEdgesDeferringSystemGestures)

Sets the screen edge from which you want your gesture to take
precedence over the system gesture.

[`var childForScreenEdgesDeferringSystemGestures: UIViewController?`](/documentation/SwiftUI/UIHostingController/childForScreenEdgesDeferringSystemGestures)

### Accessing the available key commands

[`var keyCommands: [UIKeyCommand]?`](/documentation/SwiftUI/UIHostingController/keyCommands)

### Managing undo

[`var undoManager: UndoManager?`](/documentation/SwiftUI/UIHostingController/undoManager)

### Instance Properties

[`var childViewControllerForPreferredContainerBackgroundStyle: UIViewController?`](/documentation/SwiftUI/UIHostingController/childViewControllerForPreferredContainerBackgroundStyle)

[`var preferredContainerBackgroundStyle: UIContainerBackgroundStyle`](/documentation/SwiftUI/UIHostingController/preferredContainerBackgroundStyle)

### Instance Methods

[`func addChild(UIViewController)`](/documentation/SwiftUI/UIHostingController/addChild(_:))

[`func canPerformAction(Selector, withSender: Any?) -> Bool`](/documentation/SwiftUI/UIHostingController/canPerformAction(_:withSender:))

## Relationships

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSTouchBarProvider`](/documentation/AppKit/NSTouchBarProvider)

[`UIActivityItemsConfigurationProviding`](/documentation/UIKit/UIActivityItemsConfigurationProviding)

[`Copyable`](/documentation/Swift/Copyable)

[`UIUserActivityRestoring`](/documentation/UIKit/UIUserActivityRestoring)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`UIPasteConfigurationSupporting`](/documentation/UIKit/UIPasteConfigurationSupporting)

[`UITraitChangeObservable-67e94`](/documentation/UIKit/UITraitChangeObservable-67e94)

[`UIContentContainer`](/documentation/UIKit/UIContentContainer)

[`Equatable`](/documentation/Swift/Equatable)

[`UIAppearanceContainer`](/documentation/UIKit/UIAppearanceContainer)

[`Escapable`](/documentation/Swift/Escapable)

[`UITraitEnvironment`](/documentation/UIKit/UITraitEnvironment)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSExtensionRequestHandling`](/documentation/Foundation/NSExtensionRequestHandling)

[`UIStateRestoring`](/documentation/UIKit/UIStateRestoring)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`UIResponderStandardEditActions`](/documentation/UIKit/UIResponderStandardEditActions)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`UIFocusEnvironment`](/documentation/UIKit/UIFocusEnvironment)

### Inherits From

[`UIViewController`](/documentation/UIKit/UIViewController)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)