<!--
{
  "availability" : [
    "iOS: 14.0.0 - 27.2.0",
    "iPadOS: 14.0.0 - 27.2.0",
    "macCatalyst: 14.0.0 - 27.2.0",
    "macOS: 11.0.0 - 27.2.0",
    "visionOS: 1.0.0 - 27.2.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/FileDocument/init(configuration:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI12FileDocumentP13configurationxAA0cD17ReadConfigurationV_tKcfc"
  },
  "title" : "init(configuration:)"
}
-->

# init(configuration:)

Creates a document and initializes it with the contents of a file.

```
init(configuration: Self.ReadConfiguration) throws
```

## Parameters

`configuration`

Information about the file that you read
document data from.

## Discussion

SwiftUI calls this initializer when someone opens a file type
that matches one of those that your document type supports.
Use the [`file`](/documentation/SwiftUI/FileDocumentReadConfiguration/file) property of the
`configuration` input to get document’s data. Deserialize the data,
and store it in your document’s data structure:

```
init(configuration: ReadConfiguration) throws {
    guard let data = configuration.file.regularFileContents
    else { /* Throw an error. */ }
    model = try JSONDecoder().decode(Model.self, from: data)
}
```

The above example assumes that you define `Model` to contain
the document’s data, that `Model` conforms to the
<doc://com.apple.documentation/documentation/Swift/Codable> protocol,
and that you store a `model` property of that type inside your document.

> Note: SwiftUI calls this method on a background thread. Don’t
> make user interface changes from that thread.

---

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)