TechnologiesSwiftUIDocuments

FileDialogBrowserOptions struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The way that file dialogs present the file system.

How it works

FileDialogBrowserOptions is an option set that tunes the chrome and behavior of the system file browser that SwiftUI presents for import and export operations. When you open a panel with a modifier like fileImporter or fileExporter, the dialog ships with platform defaults; FileDialogBrowserOptions lets you override those defaults to control things like whether hidden files are shown, whether the user may pick directories, and how selection is enforced. Reach for it when the standard dialog is close to what you want but you need to relax or tighten one of its built-in rules.

  1. Apply the options with fileDialogBrowserOptions(_:)

    The options are injected into the environment with the fileDialogBrowserOptions(_:) view modifier, which applies to any file dialog presented from that part of the hierarchy. In the example it is attached after the presentation modifier as .fileDialogBrowserOptions(.includeHiddenFiles), so the next dialog raised within that view adopts the configuration.

  2. Pair it with the dialog presenter

    FileDialogBrowserOptions only takes effect when there is a dialog to configure, so it sits alongside a presenter modifier. Here the panel is raised by .fileImporter(isPresented: $importing, allowedContentTypes: [.folder]), and the browser options modifier on the same chain customizes that importer's browser before it appears.

  3. Combine flags as an option set

    Because FileDialogBrowserOptions conforms to OptionSet, you select behaviors as static members and union them together. The example passes the single member .includeHiddenFiles; you can OR several members in a single value to layer multiple behaviors, such as also permitting directory selection or disabling multiple selection.

  4. Let the included files reach your result handler

    The options shape what the browser exposes, which in turn changes what can flow back through the dialog's completion. In the example the selection arrives in the result closure of fileImporter, where if case .success(let url) = result unwraps the chosen URL and picked = url.lastPathComponent records it — including items the option set made selectable.

Try it — Remove the .fileDialogBrowserOptions(.includeHiddenFiles) line and reopen the dialog with the "Choose Folder" button: dot-prefixed hidden folders disappear from the browser, showing exactly what the option toggled on.

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.

FileDialogBrowserOptions.swift
struct FileDialogBrowserOptionsDemo: View {
    @State private var importing = false
    @State private var picked = "No folder selected"

    var body: some View {
        VStack(spacing: 16) {
            Image(systemName: "folder.badge.gearshape")
                .font(.largeTitle)
            Text(picked)
                .font(.callout)
            Button("Choose Folder") { importing = true }
                .buttonStyle(.borderedProminent)
        }
        .padding()
        .fileImporter(isPresented: $importing, allowedContentTypes: [.folder]) { result in
            if case .success(let url) = result { picked = url.lastPathComponent }
        }
        .fileDialogBrowserOptions(.includeHiddenFiles)
    }
}
Live preview
No folder selected Choose Folder
No folder selected Choose Folder
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →