How to remove unused Help menu item from SwiftUI app

I've built a SwiftUI app which gives me a bonus Mac app.

My app was rejected by the App Store because it has a help menu that doesn't actually function.

The rejection said:
"Specifically, the help tab will display an error. It would be appropriate to implement this feature or remove it from the binary."

Does anyone know how to actually remove this from the binary? It's such a simple app, with a single function, so it really doesn't need a help item. Can't seem to find anything about this online.
Answered by DTS Engineer in 612332022
You can use the UIMenuBuilder api to do this.

"To add and remove menus from the menu bar using the main menu system, override buildMenu(with:) in your app delegate."

For example, to remove that menu, you could do something like the following in your app delegate:

Code Block
// Inside AppDelegate.
override func buildMenu(with builder: UIMenuBuilder) {
        super.buildMenu(with: builder)
        builder.replaceChildren(ofMenu: .help) { _ in
            []
        }
    }

Accepted Answer
You can use the UIMenuBuilder api to do this.

"To add and remove menus from the menu bar using the main menu system, override buildMenu(with:) in your app delegate."

For example, to remove that menu, you could do something like the following in your app delegate:

Code Block
// Inside AppDelegate.
override func buildMenu(with builder: UIMenuBuilder) {
        super.buildMenu(with: builder)
        builder.replaceChildren(ofMenu: .help) { _ in
            []
        }
    }

I got this exact same rejection on my macOS build of a SwiftUI App.
I added the following to the AppDelegate (replace the url with your website) and it passed no problem.

Code Block    
override func buildMenu(with builder: UIMenuBuilder) {
        super.buildMenu(with: builder)
        builder.remove(menu: .services)
        builder.remove(menu: .format)
        builder.remove(menu: .toolbar)
    }
@IBAction func showHelp(_ sender: Any) {
        UIApplication.shared.open(URL(string: "https://www.yourwebsite.com")!)
    }


In your Xcode project for the Mac application, there should be a Main.storyboard file. Open it up (it will open in Interface Builder). What you should see is the menu bar for your app. Select the "Help" menu item and hit the delete key. Re-build.

You can also edit the menu to remove other items in the menu items, and the items they contain, etc., that also don't make sense for your application

Thanks so much guys! This issue is now resolved. I ended up going with the AppDelegate override but both options from @gchiste and @jmcsmith.

Thanks also @jonprescott. Because I didn’t utilise the storyboard view (I built only in code) and also built iOS first, I couldn’t find the bits you referenced. Probably just due to my approach to the build. Thanks though too!
I also wanted to throw in my two cents on this topic. I currently am developing a SwiftUI based Mac app that does not use Catalyst so UIMenuBuilder is not an option. My solution was to create a new MainMenu.xib file (which would allow me to graphically manage the menu bar) and link it up by creating a NSApplicationDelegate in my application's main SwiftUI file. Within my newly created AppDelegate I pointed it towards the MainMenu.xib file that I had previously created.

Here is my example:

Code Block
import SwiftUI
@main
struct SidebarApp: App {
    @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
class AppDelegate: NSObject, NSApplicationDelegate {
    @IBOutlet var window: NSWindow!
    func applicationDidFinishLaunching(_ aNotification: Notification) {
        let nib = NSNib(nibNamed: NSNib.Name("MainMenu"), bundle: Bundle.main)
        nib?.instantiate(withOwner: NSApplication.shared, topLevelObjects: nil)
    }
    func applicationWillTerminate(_ aNotification: Notification) {  
    }
}


Once this is setup I was able to add/remove any Menu Bar item in a graphical way from the xib file. It is worth noting that this will override any Menu Bar items that were declared within the application itself. For me this was not too big of a deal as I would gladly recreate these items if it allowed me to simply remove the Help menu...
How to remove unused Help menu item from SwiftUI app
 
 
Q