FileWrapperDocumentWriter
A document writer that serializes a snapshot into a FileWrapper.
Declaration
struct FileWrapperDocumentWriter<Snapshot>Overview
The makeFileWrapper closure in init(_:makeFileWrapper:) turns the document’s snapshot into a FileWrapper that SwiftUI writes to disk. It receives the current snapshot and, when available, the FileWrapper from the document’s last read or write. For documents written as a single file, ignore previous and return a freshly built wrapper:
extension TextDocument: WritableDocument {
func writer(
configuration: sending WriteConfiguration
) -> sending FileWrapperDocumentWriter<String> {
FileWrapperDocumentWriter(configuration) { snapshot, _ in
FileWrapper(regularFileWithContents: Data(snapshot.utf8))
}
}
// ...
}