.fileExporter issue

In sample code Building a Great Mac App with SwiftUI | Apple Developer Documentation, selecting Export… from the menu does nothing.

It looks like .fileExporter needs to be applied to the the enclosing Section instead of the Button.

CommandGroup(replacing: .importExport) {
    Section {
        Button("Export…") {
            isShowingExportDialog = true
        }
    }
    // Doesn't work when it is applied to the button,
    // but works when applied to the section
    .fileExporter(
        isPresented: $isShowingExportDialog, document: store,
        contentType: Store.readableContentTypes.first!) { result in
        }
}

Replies

yea I put it as high in the hierarchy as I can. for me that's generally on the content() view - makes it easy to know where it is, particularly if u want to call it from multiple different places

var body: some View {
       content()
             .fileImporter {}
             .fileExporter {} 
}

func content() -> some View {
       //all the other views
}