TechnologiesSwiftUI

ReferenceFileDocumentConfiguration struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The properties of an open reference file document.

How it works

ReferenceFileDocumentConfiguration is the value SwiftUI passes to the editor view of a document-based app whose model conforms to ReferenceFileDocument — a reference type, typically an ObservableObject, as opposed to the value-type FileDocument. It bundles together everything the editing view needs to work with one open document: a reference to the document object, a binding it can use to mark the document as edited, and read-only access to the file's identity. Reach for it inside the content closure of a DocumentGroup that you build with a ReferenceFileDocument, where SwiftUI gives you a configuration whose members drive the editing surface.

  1. Receive the configuration from DocumentGroup

    When you create a DocumentGroup around a ReferenceFileDocument, the trailing content closure hands you a ReferenceFileDocumentConfiguration value rather than the document directly. That single value is the entry point to the document and its metadata; the editor in the example stands in for the view you return from that closure, where the configuration would be in scope.

  2. Edit the model through configuration.document

    The document property holds the live reference to your ReferenceFileDocument instance. Because the model is a class, you mutate it in place and SwiftUI observes the change through ObservableObject — the @State text in the demo plays the role of that shared, mutable model that the TextEditor reads and writes via the $text binding.

  3. Signal changes with the isEditedBinding

    Unlike value-type documents, a reference document doesn't change identity when its contents change, so the configuration exposes an isEditedBinding (often projected as $document) that you set to tell SwiftUI the document is dirty and should be saved. The demo's caption "Edits flow to configuration.$document" points at exactly this hand-off from the editor back to the document scene.

  4. Read the file identity from fileURL

    The configuration also surfaces the document's location through fileURL, which is nil for an as-yet-unsaved document and otherwise gives you the file on disk — useful for showing a title or path. The demo's fileName label, shown with Label and the doc.text system image, illustrates where you would present that identity in the editor's chrome.

Try it — Change the fileName constant from "Untitled.md" to "README.md" to see how the value you would read from configuration.fileURL drives the title shown in the editor.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

ReferenceFileDocumentConfiguration.swift
struct ReferenceFileDocumentConfigurationDemo: View {
    @State private var text = "# Notes\nHello, world!"
    let fileName = "Untitled.md"

    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Label(fileName, systemImage: "doc.text")
                .font(.headline)
            TextEditor(text: $text)
                .font(.body.monospaced())
                .frame(height: 140)
                .overlay(
                    RoundedRectangle(cornerRadius: 8)
                        .stroke(.secondary.opacity(0.4))
                )
            Text("Edits flow to configuration.$document")
                .font(.caption)
                .foregroundStyle(.secondary)
        }
        .padding()
    }
}
Live preview
# Notes\nHello, world! Edits flow to configuration.$document
# Notes\nHello, world! Edits flow to configuration.$document
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →