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

# DocumentReader

A type that reads a document’s content from a file.

```
protocol DocumentReader<Snapshot>
```

## Overview

SwiftUI calls your document’s [`reader(configuration:)`](/documentation/SwiftUI/ReadableDocument/reader(configuration:))
method to obtain a `DocumentReader`, then invokes
[`read(from:progress:)`](/documentation/SwiftUI/DocumentReader/read(from:progress:)) in the background with coordinated
file access. The returned snapshot is delivered to
[`apply(snapshot:previous:)`](/documentation/SwiftUI/ReadableDocument/apply(snapshot:previous:)) on the main actor.

Use [`FileWrapperDocumentReader`](/documentation/SwiftUI/FileWrapperDocumentReader) for cases that don’t require
custom file read logic. Implement a
`DocumentReader` when you need direct URL access for
frameworks like Core Graphics, AVFoundation, or PDFKit:

```
struct ImageReader: DocumentReader {
    @concurrent
    func read(from source: URL, progress: consuming Subprogress)
        async throws -> sending CGImage {
        guard let provider =
            CGDataProvider(url: source as CFURL),
              let image = CGImage(
                  jpegDataProviderSource: provider,
                  decode: nil, shouldInterpolate: true,
                  intent: .defaultIntent
              ) else {
            throw CocoaError(.fileReadCorruptFile)
        }
        return image
    }
}
```

SwiftUI provides the document’s file URL as the reader’s source.

## Topics

### Reading a document

[`read(from:progress:)`](/documentation/SwiftUI/DocumentReader/read(from:progress:))

Reads the document’s content from disk.

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

The type representing the document’s content after reading.

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

The type of the source location to read from.

## Relationships

### Conforming Types

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

---

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)