SwiftUI App has disabled keyboard shortcuts on MacOS.

As in a title: even empty new app has menu with working menu items, but with disabled and not working keyboard shortcuts. Is it bug, feature or I should do something to enable them?

Minimize, Zoom... works.

My Edit Menu have the same problem:

Commands Undo, Redo and Delete works when chosen from menu, but calling them via keyboard causes only cursor disappear.

Replies

The keyboard shortcuts appearing disabled is the standard look for menu items in recent versions of macOS. If you look at the menus in Xcode the keyboard shortcuts look disabled but they work.

I can't reproduce what you're experiencing. The keyboard shortcuts work in my SwiftUI Mac app projects. I created a new SwiftUI Mac app project in Xcode 13.2, and pressing Cmd-M minimizes the window. What are you seeing isn't expected behavior. You shouldn't have to write any code to make the standard keyboard shortcuts work.

  • Hm, You have partially right ;) System added buttons work, but Delete button — which is custom — doesn't.

    """

    struct MyApp: App {

        var body: some Scene {         DocumentGroup(newDocument: { MyDocument() }) { group in             ContentView(document: group.document)                 .navigationSubtitle(group.document.name)         }         .commands {             CommandGroup(replacing: CommandGroupPlacement.pasteboard) {                 Button("Delete") {                     deleteSelectedObject.send()                 }                 .keyboardShortcut(.delete, modifiers: [])             }         } ...     } } """

Add a Comment