---
title: "init(coder:)"
framework: swiftui
role: symbol
role_heading: Initializer
path: "swiftui/nshostingcontroller/init(coder:)"
---

# init(coder:)

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

## Declaration

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

## Parameters

- `coder`: The decoder to use during initialization.

## Discussion

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:) method instead.

## See Also

### Creating a hosting controller object

- [init(rootView:)](swiftui/nshostingcontroller/init(rootview:).md)
- [init(coder:rootView:)](swiftui/nshostingcontroller/init(coder:rootview:).md)
