<!--
{
  "availability" : [
    "macOS: 10.15.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/NSHostingController/init(coder:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI19NSHostingControllerC5coderACyxGSgSo7NSCoderC_tcfc"
  },
  "title" : "init(coder:)"
}
-->

# init(coder:)

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

```
@MainActor @preconcurrency required dynamic init?(coder: NSCoder)
```

## Parameters

`coder`

The decoder to use during initialization.

## Discussion

The default implementation of this method throws an exception. To create
your view controller from an archive, override this method and
initialize the superclass using the
[`init(coder:rootView:)`](/documentation/SwiftUI/NSHostingController/init(coder:rootView:)) method instead.

---

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)