Chapter 3: Menus issues

Could I just ask some questions about Commands?

1)Is it possible to enable/disable New Window menu item?

2)Is it possible to create a CommandMenu between File and Edit?
CommandMenu

thanks

@Sarah any suggestions?

Hi,

  1. As far as I know, you cannot enable or disable the existIng New Window menu item. But you can replace it with your own version that you can control:
@State private var disableNew = false

// ...

CommandGroup(replacing: .newItem) {
  Button("New Window") {
    // open a new window manually
    NSApp.mainWindow?.windowController?.newWindowForTab(nil)
  }
  .disabled(disableNew)
}
  1. No. When you add a CommandMenu, it will always be placed between the View and Window menus.

Sarah

@sarah
I got it.
I need to switch to AppKit to control some UI components.
So, can I say that the SwiftUI is not ready for macOS. right?
thanks for help.

I would say that SwiftUI is ready for macOS but just like in iOS, SwiftUI does not yet have equivalents for every UI element and interaction.

I think it will be a long time before we can do without AppKit/UIKit completely, but starting with SwiftUI and adding these still makes for an easier development process.

1 Like