Skip to content

Use .fileImporter view modifier instead of DocumentPickerView #1198

Description

@rolson

SwiftUI now has a way to import files without wrapping the UIDocumentPickerViewController: .fileImporter(...):

        .toolbar {
            ToolbarItem(placement: .topBarTrailing) {
                Button("Import File", systemImage: "folder") {
                    isShowingFileImporter = true
                }
                .labelStyle(.iconOnly)
                .fileImporter(
                    isPresented: $isShowingFileImporter,
                    allowedContentTypes: [...]
                ) { result in
                    switch result {
                    case .success(let fileURL):
                        ...
                    case .failure(let error):
                        ...
                    }
                }
            }
        }

cc @CalebRas

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions