---
title: FileDocument
framework: swiftui
role: symbol
role_heading: Protocol
path: swiftui/filedocument
---

# FileDocument

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

## Declaration

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

## Overview

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. 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. Loads documents from file in the init(configuration:) initializer. Stores documents to file by serializing their content in the 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 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 ReferenceFileDocument instead.

## Topics

### Reading a document

- [init(configuration:)](swiftui/filedocument/init(configuration:).md)
- [readableContentTypes](swiftui/filedocument/readablecontenttypes.md)
- [FileDocument.ReadConfiguration](swiftui/filedocument/readconfiguration.md)

### Writing a document

- [fileWrapper(configuration:)](swiftui/filedocument/filewrapper(configuration:).md)
- [writableContentTypes](swiftui/filedocument/writablecontenttypes.md)
- [FileDocument.WriteConfiguration](swiftui/filedocument/writeconfiguration.md)

## Relationships

### Inherits From

- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Storing document data in a value type

- [FileDocumentConfiguration](swiftui/filedocumentconfiguration.md)
