Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a CommandMenu within a CommandGroup?

Tags:

swiftui

I would like to create a menu at the import/export location.

CommandGroup(replacing: CommandGroupPlacement.importExport) {
       CommandMenu("Import"){
                Button("Format I (.f1)"){
                    print("import Format 1")
                }
                Button ("Format II (.f2)") {
                    print("import Format 2")
                }
            }
        }

Unfortunately, CommandMenu isn't a View but a Command. So, how do I combine these two?

like image 693
Wizard of Kneup Avatar asked Feb 16 '26 20:02

Wizard of Kneup


1 Answers

Try the following

CommandGroup(replacing: CommandGroupPlacement.importExport) {
    Menu("Import") {                                            // << here !!
            Button("Format I (.f1)"){
                print("import Format 1")
            }
            Button ("Format II (.f2)") {
                print("import Format 2")
            }
        }
    }
like image 135
Asperi Avatar answered Feb 20 '26 03:02

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!