How do I add MenuItem to menubar in macos using SwiftUI?

The new SwiftUI introduces the new Menu item but I cannot find any complete examples showing how to use it.

I did find an article (cannot link to it here) on how to use Menu but it is connected to a toolbar item only and does not change the menubar.

I would like to add a menu item to the menubar in macOS using a SwiftUI App. Any examples of how to do this would be great.
Answered by michelXav in 654271022
Apple has a tutorial in which you build a multi-platform app in SwiftUI that showcases inserting a menu command in the macOS version. You can find it here. The macOS bit is at the end. Hope it helps.
Accepted Answer
Apple has a tutorial in which you build a multi-platform app in SwiftUI that showcases inserting a menu command in the macOS version. You can find it here. The macOS bit is at the end. Hope it helps.
Thanks, that did help.

For completeness, I wrote this small sample app that adds a new menu item to the menu and overrides the copy menu.

Code Block
@main
struct MenuTestApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
    .commands {
      CommandMenu("My Top Menu") {
        Button("Sub Menu Item") { print("You pressed sub menu.") }
          .keyboardShortcut("S")
      }
      CommandGroup(replacing: .pasteboard) {
        Button("Cut") { print("Cutting something...") }
          .keyboardShortcut("X")
        Button("Copy") { print("Copying something...") }
          .keyboardShortcut("C")
        Button("Paste") { print("Pasting something...") }
          .keyboardShortcut("V")
        Button("Paste and Match Style") { print("Pasting and Matching something...") }
          .keyboardShortcut("V", modifiers: [.command, .option, .shift])
        Button("Delete") { print("Deleting something...") }
          .keyboardShortcut(.delete)
        Button("Select All") { print("Selecting something...") }
          .keyboardShortcut("A")
      }
    }
  }
}


How do I add MenuItem to menubar in macos using SwiftUI?
 
 
Q