<!--
{
  "availability" : [
    "iOS: 14.0.0 - 27.0.0",
    "iPadOS: 14.0.0 - 27.0.0",
    "macCatalyst: 14.0.0 - 27.0.0",
    "macOS: 11.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/FileDocument",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI12FileDocumentP"
  },
  "title" : "FileDocument"
}
-->

# FileDocument

A type that you use to serialize documents to and from file.

```
@preconcurrency protocol FileDocument : Sendable
```

## Overview

To store a document as a value type — like a structure — create a type
that conforms to the `FileDocument` protocol and implement the
required methods and properties. Your implementation:

- Provides a list of the content types that the document can read from and
  write to by defining [`readableContentTypes`](/documentation/SwiftUI/FileDocument/readableContentTypes). If the list of content
  types that the document can write to is different from those that it reads
  from, you can optionally also define [`writableContentTypes`](/documentation/SwiftUI/FileDocument/writableContentTypes).
- Loads documents from file in the [`init(configuration:)`](/documentation/SwiftUI/FileDocument/init(configuration:)) initializer.
- Stores documents to file by serializing their content in the
  [`fileWrapper(configuration:)`](/documentation/SwiftUI/FileDocument/fileWrapper(configuration:)) method.

> Note: The `fileWrapper(configuration:)` method can either serialize
> the whole document into a single file, or use a document package
> — a directory ``FileWrapper`` — to store the document as a
> collection of files. With a package, you can improve performance
> by rewriting only the specific files that changed since the last
> save. For examples, see ``doc://com.apple.SwiftUI/documentation/SwiftUI/FileDocument/fileWrapper(configuration:)``.

Ensure that types that conform to this protocol are `Sendable`.
In particular, SwiftUI calls the protocol’s methods from different isolation domains.
Don’t perform serialization and deserialization on `MainActor`.

> Important: If you store your document as a reference type — like a
> class — use ``doc://com.apple.SwiftUI/documentation/SwiftUI/ReferenceFileDocument`` instead.

## Topics

### Reading a document

[`init(configuration:)`](/documentation/SwiftUI/FileDocument/init(configuration:))

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

[`readableContentTypes`](/documentation/SwiftUI/FileDocument/readableContentTypes)

The file and data types that the document reads from.

[`FileDocument.ReadConfiguration`](/documentation/SwiftUI/FileDocument/ReadConfiguration)

The configuration for reading document contents.

### Writing a document

[`fileWrapper(configuration:)`](/documentation/SwiftUI/FileDocument/fileWrapper(configuration:))

Serializes a document snapshot to a file wrapper.

[`writableContentTypes`](/documentation/SwiftUI/FileDocument/writableContentTypes)

The file types that the document supports saving or exporting to.

[`FileDocument.WriteConfiguration`](/documentation/SwiftUI/FileDocument/WriteConfiguration)

The configuration for writing document contents.



---

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)