<!--
{
  "availability" : [
    "iOS: 14.0.0 - 27.2.0",
    "iPadOS: 14.0.0 - 27.2.0",
    "macCatalyst: 14.0.0 - 27.2.0",
    "macOS: 11.0.0 - 27.2.0",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ReferenceFileDocument/fileWrapper(snapshot:configuration:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI21ReferenceFileDocumentP11fileWrapper8snapshot13configurationSo06NSFileG0C8SnapshotQz_AA0dE18WriteConfigurationVtKF"
  },
  "title" : "fileWrapper(snapshot:configuration:)"
}
-->

# fileWrapper(snapshot:configuration:)

Serializes a document snapshot to a file wrapper.

```
func fileWrapper(snapshot: Self.Snapshot, configuration: Self.WriteConfiguration) throws -> FileWrapper
```

## Parameters

`snapshot`

The document snapshot to save.

`configuration`

Information about a file that already exists for the
document, if any.

## Return Value

The destination to serialize the document contents to. The
value can be a newly created
<doc://com.apple.documentation/documentation/Foundation/FileWrapper>
or an update of the one provided in the `configuration` input.

## Discussion

To store a document — for example, in response to a Save command —
SwiftUI begins by calling the [`snapshot(contentType:)`](/documentation/SwiftUI/ReferenceFileDocument/snapshot(contentType:)) method to get
a copy of the document data in its current state. Then SwiftUI passes
that snapshot to this method, where you serialize it and create or
modify a file wrapper with the serialized data:

```
func fileWrapper(snapshot: Snapshot, configuration: WriteConfiguration) throws -> FileWrapper {
    let data = try JSONEncoder().encode(snapshot)
    return FileWrapper(regularFileWithContents: data)
}
```

SwiftUI disables document edits during the snapshot to ensure that the
document’s data remains coherent, but reenables edits during the
serialization operation.

> Note: SwiftUI calls this method on a background thread. Don’t
> make user interface changes from that thread.

---

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)