<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/FileWrapperDocumentWriter",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI25FileWrapperDocumentWriterV"
  },
  "title" : "FileWrapperDocumentWriter"
}
-->

# FileWrapperDocumentWriter

A document writer that serializes a snapshot into a `FileWrapper`.

```
struct FileWrapperDocumentWriter<Snapshot>
```

## Overview

The `makeFileWrapper` closure in
[`init(_:makeFileWrapper:)`](/documentation/SwiftUI/FileWrapperDocumentWriter/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))
        }
    }

    // ...
}
```

## Topics

### Creating a writer

[`init(_:makeFileWrapper:)`](/documentation/SwiftUI/FileWrapperDocumentWriter/init(_:makeFileWrapper:))

Creates a writer that converts a snapshot into a `FileWrapper`.

[`WriteConfiguration`](/documentation/SwiftUI/FileWrapperDocumentWriter/WriteConfiguration)

### Writing a document

## Relationships

### Conforms To

[`DocumentWriter`](/documentation/SwiftUI/DocumentWriter)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)