Contents

FileDocument

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

Declaration

@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:

Because FileDocument is a value type, SwiftUI automatically registers an undo action whenever your document’s value changes. You don’t need to call UndoManager/registerUndo(withTarget:handler:) yourself.

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.

Topics

Reading a document

Writing a document

See Also

Deprecated