FileDocument
protocol · iOS 14.0+ · Deprecated in iOS 100000.0 · SDK 27.1
@preconcurrency protocol FileDocument : SendableA type that you use to serialize documents to and from file. 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-2opfc``. * 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:)``. 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``. > Important: If you store your document as a reference type --- like a class --- use ``ReferenceFileDocument`` instead. Because SwiftUI can't detect changes to a reference type's properties on its own, you're responsible for registering undo actions yourself.
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
FileDocument.writableContentTypes
Static protocol requirements cannot be called through an instance.