I am currently building a macOS project using SwiftUI. When I create the project, Main.storyboard file gets created automatically. I found some solution (here) to remove Main.storyboard file after setting the user interface as storyboard. But I did not find a way to delete the Main.storyboard when the user interface is SwiftUI. Any help would be appreciated! I have attached a screenshot of the macOS project with SwiftUI as the interface.
Yes, here are the steps:
Delete the Main.storyboard from your project (to Trash)
Remove the Main reference in the General tab of your target:

On macOS there should not be any reference to the storyboard in the plist file so nothing to do, but you need to remove the @NSApplicationMain from your App Delegate:

Now your project does not have any entry point so it will complain about a missing _main symbol. So create a main.swift file with the following content:
import AppKit
let app = NSApplication.shared
let delegate = AppDelegate()
app.delegate = delegate
app.run()
As others pointed out, you will lose the default menu of macOS (that's actually why I use this technique), so to create a menu programmatically add the following at the top of the applicationDidFinishLaunching method of your AppDelegate to add what you need:
let appMenu = NSMenuItem()
appMenu.submenu = NSMenu()
appMenu.submenu?.addItem(NSMenuItem(title: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
let mainMenu = NSMenu(title: "My App")
mainMenu.addItem(appMenu)
NSApplication.shared.mainMenu = mainMenu
Cheers
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