<!--
{
  "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:)`](/documentation/SwiftUI/UIHostingController/init(rootView:))

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

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

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

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

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

### Responding to view-related events

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

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

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

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

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

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

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

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

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

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

[`viewWillTransition(to:with:)`](/documentation/SwiftUI/UIHostingController/viewWillTransition(to:with:))

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

[`target(forAction:withSender:)`](/documentation/SwiftUI/UIHostingController/target(forAction:withSender:))

[`rootView`](/documentation/SwiftUI/UIHostingController/rootView)

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

### Checking for modality

[`isModalInPresentation`](/documentation/SwiftUI/UIHostingController/isModalInPresentation)

### Managing the size

[`sizingOptions`](/documentation/SwiftUI/UIHostingController/sizingOptions)

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

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

[`sizeThatFits(in:)`](/documentation/SwiftUI/UIHostingController/sizeThatFits(in:))

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

[`safeAreaRegions`](/documentation/SwiftUI/UIHostingController/safeAreaRegions)

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

### Configuring the status bar

[`preferredStatusBarStyle`](/documentation/SwiftUI/UIHostingController/preferredStatusBarStyle)

The preferred status bar style for the view controller.

[`preferredStatusBarUpdateAnimation`](/documentation/SwiftUI/UIHostingController/preferredStatusBarUpdateAnimation)

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

[`prefersStatusBarHidden`](/documentation/SwiftUI/UIHostingController/prefersStatusBarHidden)

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

[`childForStatusBarStyle`](/documentation/SwiftUI/UIHostingController/childForStatusBarStyle)

[`childForStatusBarHidden`](/documentation/SwiftUI/UIHostingController/childForStatusBarHidden)

### Configuring the home indicator

[`prefersHomeIndicatorAutoHidden`](/documentation/SwiftUI/UIHostingController/prefersHomeIndicatorAutoHidden)

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

[`childForHomeIndicatorAutoHidden`](/documentation/SwiftUI/UIHostingController/childForHomeIndicatorAutoHidden)

### Configuring the interface appearance

[`preferredUserInterfaceStyle`](/documentation/SwiftUI/UIHostingController/preferredUserInterfaceStyle)

The preferred interface style for this view controller.

[`preferredScreenEdgesDeferringSystemGestures`](/documentation/SwiftUI/UIHostingController/preferredScreenEdgesDeferringSystemGestures)

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

[`childForScreenEdgesDeferringSystemGestures`](/documentation/SwiftUI/UIHostingController/childForScreenEdgesDeferringSystemGestures)

### Accessing the available key commands

[`keyCommands`](/documentation/SwiftUI/UIHostingController/keyCommands)

### Managing undo

[`undoManager`](/documentation/SwiftUI/UIHostingController/undoManager)



---

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)