applicationDidFinishLaunching未调用,使用storyboards和swift3

Sam*_*pak 7 cocoa xcode-storyboard swift3

applicationDidFinishLaunching当我运行我的应用程序不会被调用.

这是我AppDelegate班级的代码:

@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
    }


}
Run Code Online (Sandbox Code Playgroud)

我正在为我的应用程序使用Swift 3故事板.

applicationDidFinishLaunching的答案- 不触发建议连接AppDelegate.swift到故事板中的应用程序对象.我那里没有任何应用程序对象.

我的应用程序没有主菜单,它是代理,因为我正在尝试构建类似于聚光灯的东西.

我该怎么做才能applicationDidFinishLaunching跑步?

vad*_*ian 8

即使您的应用程序作为代理运行,您的故事板也应该具有以下结构:

在此输入图像描述

如果没有,将蓝色立方体(对象)拖动到应用程序场景中,将对象的类设置为AppDelegate并控制 - 拖动ApplicationApp Delegate并选择delegate.

如果您甚至没有应用程序场景,请创建一个启用了故事板的新项目,删除当前的Main.storyboard文件并将新创建的项目的Main.storyboard拖到当前项目中.