<!--
{
  "availability" : [
    "iOS: 14.0.0 - 27.0.0",
    "iPadOS: 14.0.0 - 27.0.0",
    "macCatalyst: 14.0.0 - 27.0.0",
    "macOS: 11.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/DocumentGroup/init(viewing:viewer:)-6dq9n",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI13DocumentGroupVA2A04FileC0RzrlE7viewing6viewerACyxq_Gxm_q_AA0eC13ConfigurationVyxGctcfc"
  },
  "title" : "init(viewing:viewer:)"
}
-->

# init(viewing:viewer:)

Creates a document group capable of viewing file documents.

```
nonisolated init(viewing documentType: Document.Type, @ContentBuilder viewer: @escaping (FileDocumentConfiguration<Document>) -> Content)
```

## Parameters

`documentType`

The type of document your app can view.

`viewer`

The viewing UI for the provided document.

## Discussion

Use this method to create a document group that can view files of a
specific type. The example below creates a new document viewer for
`MyImageFormatDocument` and displays them with `MyImageFormatViewer`:

```
@main
struct MyApp: App {
    var body: some Scene {
        DocumentGroup(viewing: MyImageFormatDocument.self) { file in
            MyImageFormatViewer(image: file.document)
        }
    }
}
```

With the `viewing:` initializer, SwiftUI considers your app as a
viewer for given content types (readable content types declared on
the document type). No File > New menu item is added on macOS, no
New Document button appears in the iOS document browser, and the
`FileDocumentConfiguration/isEditable` property is `false`,
preventing accidental writes. Use the
`DocumentGroup/init(newDocument:editor:)` initializer instead if
your app needs to create or edit documents.

You tell the system about the app’s role with respect to the document
type by setting the
<doc://com.apple.documentation/documentation/BundleResources/Information-Property-List/CFBundleDocumentTypes/CFBundleTypeRole>
`Info.plist` key with a value of `Viewer`.

---

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)