applicationDidFinishLaunching not called, using storyboards and swift3

风格不统一 提交于 2019-12-04 01:20:49

问题


The applicationDidFinishLaunching is not being called when I run my app.

This is the code of my AppDelegate class:

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    let statusItem = NSStatusBar.system().statusItem(withLength: NSSquareStatusItemLength)

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
    }


}

I am using Swift 3 and storyboards for my app.

The answer to applicationDidFinishLaunching - not triggering suggests to connect AppDelegate.swift to application object in storyboard. I don't have any application object there.

My app does not have main menu, it is agent, as I am trying to build something similar to spotlight.

What should I do to get applicationDidFinishLaunching running?


回答1:


Even if your app is running as an agent your storyboard is supposed to have this structure:

If not, drag a blue cube (object) into the application scene, set the class of the object to AppDelegate and control-drag from Application to App Delegate and select delegate.

If you even have no Application Scene, create a new project with storyboard enabled, delete your current Main.storyboard file and drag the Main.storyboard of the new created project into your current project.



来源:https://stackoverflow.com/questions/42472371/applicationdidfinishlaunching-not-called-using-storyboards-and-swift3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!