---
title: "init(configuration:)"
framework: swiftui
role: symbol
role_heading: Initializer
path: "swiftui/referencefiledocument/init(configuration:)"
---

# init(configuration:)

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

## Declaration

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

## Parameters

- `configuration`: Information about the file that you read document data from.

## Discussion

Discussion SwiftUI calls this initializer when someone opens a file type that matches one of those that your document type supports. Use the 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 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.

## See Also

### Reading a document

- [readableContentTypes](swiftui/referencefiledocument/readablecontenttypes.md)
- [ReferenceFileDocument.ReadConfiguration](swiftui/referencefiledocument/readconfiguration.md)
