Dual .fileImporter modifier only one is called

On macOS I'm seeing that only one .fileImporter modifier is called when two are defined. Anybody seeing the same issue?

The scenario I have is two different file sources share the same file extension but they need to be loaded by two slightly different processes.

Select the first option. Nothing happens. Select the second option, it works. Seeing this also in another project.

Because the isPresented value is a binding, it isn't straightforward to logically OR the boolean @States and conditionally extract within the import closure.

@main
struct Dual_File_Importer_ExpApp: App {
    
    @State private var showFirstDialog = false
    @State private var showSecondDialog = false
    
    
    var body: some Scene {
        DocumentGroup(newDocument: Dual_File_Importer_ExpDocument()) { file in
            ContentView(document: file.$document)
                .fileImporter(isPresented: $showFirstDialog, allowedContentTypes: [.commaSeparatedText]) { result in
                    print("first")
                }
                .fileImporter(isPresented: $showSecondDialog, allowedContentTypes: [.commaSeparatedText]) { result in
                    print("second")
                }
        }
        .commands {
            CommandGroup(after: .importExport)
            {
                Button("Import First")
                {
                    showFirstDialog.toggle()
                }
                
                Button("Import Second")
                {
                    showSecondDialog.toggle()
                }
            }
        }
    }
}```


I'm having the same problem. Apparently chaining .fileImporter modifiers doesn't work in SwifUI. And this doesn't seem to be documented anywhere. I'm going to take the approach of using a single .fileImporter and a separate variable to control which file type/behavior to use.

I would love to see if anyone has any other suggestions for handling multiple file importer dialogs in a single app.

This is currently not supported and we're looking into it.

If you apply the modifiers to different views, e.g., buttons, It works as expected:

Button("First import", systemImage: "folder") {
    isShowingExport.toggle()
}
.fileImporter(isPresented: $isShowingExport, allowedContentTypes: [.commaSeparatedText]) { result in
    print("first")
}


Button("Second Import", systemImage: "folder.fill") {
    exportCollection.toggle()
}
.fileImporter(isPresented: $exportCollection, allowedContentTypes: [.commaSeparatedText]) { result in
    print("second")
}
Dual .fileImporter modifier only one is called
 
 
Q