FileDocument
A type that you use to serialize documents to and from file.
Declaration
@preconcurrency protocol FileDocument : SendableOverview
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.
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.