Select directory in SwiftUI file importer

I want to show a file importer that allows to select both regular files as well as directories. When running the following code on iOS, I can tap a PDF file and the file importer closes as expected, but when tapping a directory, the file importer shows its contents. How can I instead select that directory and close the file importer? The navigation bar shows a Cancel button, but no Open button.

struct FileView: View {
    @State private var showFileImporter = false

    var body: some View {
        ScrollView {
            VStack(alignment: .leading) {
                VStack(alignment: .center) {
                    Button("Open") {
                        showFileImporter = true
                    }
                }
            }
        }
        .fileImporter(isPresented: $showFileImporter, allowedContentTypes: [.pdf, .directory], onCompletion: { result in
            // TODO
        })
    }

}

Your code works as I'd expect on macOS. Are you running on a real device or a simulator?

Use .folder instead of .directory and your Open button will be there.

Use .folder instead of .directory and your Open button will be there.

Thanks! That works, but why? Even Apple‘s sample code in the official documentation uses ˋ.directoryˋ. Why does it only work on macOS by default?

Select directory in SwiftUI file importer
 
 
Q