How can I disable or remove a menu item in a SwiftUI macOS app? For example, the Print... item is shown in the File menu by default. But my application does not use printing features. How would I remove the print item from the file menu in a SwiftUI Mac app?

I tried the following in AppDelegate.swift but it doesn't work:
import Cocoa
import SwiftUI
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillFinishLaunching(_ notification: Notification) {
if let menu = NSApplication.shared.mainMenu {
menu.item(withTitle: "File")?.submenu?.item(withTitle: "Print...")?.state = NSControl.StateValue.off
}
}
}
[per-request @Alexander]
Early SwiftUI project templates had explicit resource for main menu, Main.storyboard (or xib file). If you can find one in your project then just locate menu there and remove Print menu item manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With