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

# ReadableDocument

A document type that supports reading from file.

```
protocol ReadableDocument : AnyObject
```

## Overview

Conform to `ReadableDocument` to build a read-only document
viewer, or combine with [`WritableDocument`](/documentation/SwiftUI/WritableDocument) (via the
[`Document`](/documentation/SwiftUI/Document) protocol) for full read-write support.

A readable document is a reference type so that SwiftUI can
maintain a stable identity across updates. Use `@Observable` to
enable per-property change tracking:

```
@Observable
final class MarkdownViewer: ReadableDocument {
    static let readableContentTypes: [UTType] = [.markdown]

    var attributedText = AttributedString()

    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)
        }
    }

    @MainActor
    func apply(snapshot: sending String, previous: sending String?) async throws {
        attributedText = try AttributedString(
            markdown: snapshot
        )
    }
}
```

Present a read-only document with [`DocumentGroup`](/documentation/SwiftUI/DocumentGroup) using the
viewer initializer:

```
DocumentGroup { document in
    MarkdownView(document: document)
} makeReadableDocument: { configuration, context in
    MarkdownViewer()
}
```

Set `CFBundleTypeRole` to `Viewer` in your Info.plist for
read-only document types.

## Topics

### Reading a document

[`readableContentTypes`](/documentation/SwiftUI/ReadableDocument/readableContentTypes)

The content types this document can open.

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

The configuration for reading document contents.

[`Reader`](/documentation/SwiftUI/ReadableDocument/Reader)

A type that implements reading from disk.

[`reader(configuration:)`](/documentation/SwiftUI/ReadableDocument/reader(configuration:))

Creates a reader to load this document from disk.

[`apply(snapshot:previous:)`](/documentation/SwiftUI/ReadableDocument/apply(snapshot:previous:))

Applies a loaded snapshot to the document model.

[`writableContentTypes`](/documentation/SwiftUI/ReadableDocument/writableContentTypes)

By default, a document that supports reading also supports writing
the same content types.

## Relationships

### Inherited By

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

---

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)