Replace MainMenu.xib with a pure Swift + SwiftUI app, dropping the AppKit template scaffolding the
project has carried since it was created.
It does work
Worth stating up front, because it is easy to assume the xib is load-bearing: a SwiftUI App with no
xib at all synthesises the complete menu bar. A bundle containing only an Info.plist and a
binary produces Apple, App, Edit, View, Window, Help with no nib involved. The xib is template
residue, not a requirement.
What has to move
AppDelegate currently builds an NSWindow + NSWindowController + NSHostingView by hand. A
Settings scene replaces all of it and gets ⌘, and the menu item for free.
INFOPLIST_KEY_NSMainNibFile=MainMenu in Config/CenterMouse.xcconfig must go, along with the xib
itself.
- Menu customisation moves to
.commands { }.
Watch out for
The xib encodes an App Review accommodation. From AppDelegate:
// Excluding this from the Window menu so that it can be manually added.
// This is being done to comply with an App Review requirement.
window.isExcludedFromWindowsMenu = true
A reviewer required this once. Re-derive it deliberately in the SwiftUI version rather than
discovering during review that it was lost — this is the single riskiest part of the change.
Some things have no SwiftUI equivalent and still need an @NSApplicationDelegateAdaptor:
- The
launchedAsLogInItem check, which reads the launch Apple Event via NSAppleEventManager.
NSApp.setActivationPolicy for the Dock icon toggle.
The About panel needs no special handling as long as the credits stay a bundled resource — the
standard menu action picks them up on its own. Only reach for CommandGroup(replacing: .appInfo) if
you want behaviour beyond that.
Notes
MenuBarExtra is available (macOS 13+) if a status item is ever wanted, but note that menu bar items
were deliberately removed in 6480ee9 — this issue is not a reason to bring them back.
Verify
- Full menu bar present, all standard items functional.
⌘, opens settings; the app menu's Settings item works.
- The settings window is still excluded from the Window menu as above.
- Launching as a login item still shows no window and does not steal focus.
- Hiding the Dock icon still works, and the window can still be reopened afterwards.
Replace
MainMenu.xibwith a pure Swift + SwiftUI app, dropping the AppKit template scaffolding theproject has carried since it was created.
It does work
Worth stating up front, because it is easy to assume the xib is load-bearing: a SwiftUI
Appwith noxib at all synthesises the complete menu bar. A bundle containing only an
Info.plistand abinary produces
Apple, App, Edit, View, Window, Helpwith no nib involved. The xib is templateresidue, not a requirement.
What has to move
AppDelegatecurrently builds anNSWindow+NSWindowController+NSHostingViewby hand. ASettingsscene replaces all of it and gets⌘,and the menu item for free.INFOPLIST_KEY_NSMainNibFile=MainMenuinConfig/CenterMouse.xcconfigmust go, along with the xibitself.
.commands { }.Watch out for
The xib encodes an App Review accommodation. From
AppDelegate:A reviewer required this once. Re-derive it deliberately in the SwiftUI version rather than
discovering during review that it was lost — this is the single riskiest part of the change.
Some things have no SwiftUI equivalent and still need an
@NSApplicationDelegateAdaptor:launchedAsLogInItemcheck, which reads the launch Apple Event viaNSAppleEventManager.NSApp.setActivationPolicyfor the Dock icon toggle.The About panel needs no special handling as long as the credits stay a bundled resource — the
standard menu action picks them up on its own. Only reach for
CommandGroup(replacing: .appInfo)ifyou want behaviour beyond that.
Notes
MenuBarExtrais available (macOS 13+) if a status item is ever wanted, but note that menu bar itemswere deliberately removed in 6480ee9 — this issue is not a reason to bring them back.
Verify
⌘,opens settings; the app menu's Settings item works.