.fileExporter and .fileImporter Won’t Work inside a Menu in SwiftUI

Recently, I noticed that the newly introduced fileImporter and fileExporter view modifiers in SwiftUI won’t work inside a Menu view. It’s not a big deal to put the file modifiers outside of the menu, but it took quite a while for me to pin down the problem.

Here is an example of the issue:

First of all I’ve created a simple text file document type as it is shown here:

With this I’ve created my FileExporterView:

For completeness, I’ve also implemented my FileImporterView:

Now, let’s wrap it up to demonstrate the problem:

The separate commands in the VStack work as expected but the ones in the Menu won’t. The panels just won’t show up.

The solution is quite simple: Just put the fileImporter / fileExporter view modifiers outside the Menu. Here are the modified views:

and

and the usage in the Menu:

A little bit ugly but it works.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert