<!--
{
  "availability" : [
    "macOS: 10.15.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/NSHostingController",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI19NSHostingControllerC"
  },
  "title" : "NSHostingController"
}
-->

# NSHostingController

An AppKit view controller that hosts SwiftUI view hierarchy.

```
@MainActor @preconcurrency class NSHostingController<Content> where Content : View
```

## Overview

Create an `NSHostingController` object when you want to integrate SwiftUI
views into an AppKit 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/NSHostingController/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/NSHostingController/init(rootView:))

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

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

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

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

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

### Getting the root view

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

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

[`identifier`](/documentation/SwiftUI/NSHostingController/identifier)

### Configuring the controller

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

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

[`preferredContentSize`](/documentation/SwiftUI/NSHostingController/preferredContentSize)

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

The options for how the hosting controller’s view creates and updates
constraints based on the size of its SwiftUI content.

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

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

[`sceneBridgingOptions`](/documentation/SwiftUI/NSHostingController/sceneBridgingOptions)

The options for which aspects of the window will be managed by this
controller’s hosting view.



---

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)