I'm developing a macOS application that only consists of a menu bar icon.
I have a xib file (MenuBarMenu.xib) with the menu and a corresponding controller(MenuBarMenuController.swift) that puts it in menubar.
I want to inject dependencies in this controller, either manually or with Swinject.
So to do this I thought I could load the xib file programmatically from AppDelegate:
func applicationDidFinishLaunching(_ aNotification: Notification) {
let controller = MenuBarMenuController(nibName: "MenuBarMenu", bundle: nil)
controller.someDependency = Test()
}
But it looks like controller is being instantiated automatically by NSApplication before reaching applicationDidFinishLaunching.
What I've tried:
- Removed NSMainNibFile from info.plist
- Removed NSMainStoryboardFile from info.plist
- Cleared Main Interface setting in project settings
- Added LSUIElement = yes
- Used custom main.swift to make sure my AppDelegate is called.
If xib file is there, it's called before AppDelegate. When I delete it, there are no runtime errors.
My question is: how can I inject a dependency in this controller?