How to add items to App menu before File, Edit and View in SwiftUI?

Viewed 1108

Using the new SwiftUI App model, how can I set the items available on the Menu titled my app name (next to the Apple logo)?

Using the following

WindowGroup {
    …
}
.commands { 
    CommandMenu("Menu Name") {
        Button(action: {}) { Text("Menu Item") }
    }
}

Will place menus after File, Edit and View. I wish to add an item to the menu titled my app name.

1 Answers

Instead of using a CommandMenu, use a CommandGroup and set its positioning to be one of .appInfo, .appSettings, .appTermination, .appVisibility, or .systemServices.

For example

WindowGroup {
    …
}
.commands { 
    CommandGroup(after: .systemServices) { 
        Button(action: {}) { Text("hi") } 
    }
}
Related