<!--
{
  "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/FileWrapperDocumentReader",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI25FileWrapperDocumentReaderV"
  },
  "title" : "FileWrapperDocumentReader"
}
-->

# FileWrapperDocumentReader

A document reader that deserializes a `FileWrapper` into a snapshot.

```
struct FileWrapperDocumentReader<Snapshot>
```

## Overview

This is the recommended reader for most documents. Provide a
closure that converts a `FileWrapper` into your snapshot type,
and `FileWrapperDocumentReader` handles file coordination and
loading.

```
func reader(configuration: sending ReadConfiguration) -> sending FileWrapperDocumentReader<String> {
    FileWrapperDocumentReader(configuration) { fileWrapper in
        guard let data =
            fileWrapper.regularFileContents else {
            throw CocoaError(.fileReadCorruptFile)
        }
        return String(decoding: data, as: UTF8.self)
    }
}
```

For package documents, navigate the `FileWrapper` hierarchy:

```
FileWrapperDocumentReader(configuration) { directory in
    let children = directory.fileWrappers ?? [:]
    guard let metadataData = children["metadata.json"]?
        .regularFileContents else {
        throw CocoaError(.fileReadCorruptFile)
    }
    return try JSONDecoder().decode(
        Metadata.self, from: metadataData
    )
}
```

> Important: `FileWrapper` loads file contents on demand. A
> child file may be gone by the time you call
> `regularFileContents`. Always handle errors when reading
> children of a package.

The closure does not receive a `Subprogress`. To report
progress during reads, use a custom [`DocumentReader`](/documentation/SwiftUI/DocumentReader) instead.

## Topics

### Creating a reader

[`init(_:makeSnapshot:)`](/documentation/SwiftUI/FileWrapperDocumentReader/init(_:makeSnapshot:))

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

[`ReadConfiguration`](/documentation/SwiftUI/FileWrapperDocumentReader/ReadConfiguration)

### Reading a document

## Relationships

### Conforms To

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

---

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)