Xcode使用以下代码创建了AppDelegate.swift
import Cocoa @NSApplicationMain class AppDelegate: NSObject,NSApplicationDelegate { func applicationDidFinishLaunching(aNotification: NSNotification) { // Insert code here to initialize your application } func applicationWillTerminate(aNotification: NSNotification) { // Insert code here to tear down your application } }
@NSApplicationMain是什么意思,我的main.mm/main.m文件和main()在哪里?
解决方法
OS X apps can now apply the @NSApplicationMain attribute to their app delegate class in order to generate an implicit main for the app.
This attribute works in the same way as the @UIApplicationMain attribute for iOS apps.”
所以,基本上,这是一种使你的应用程序引导和运行的方式,而不必在一个单独的Swift文件中编写一些全局级的样板.在以前的Xcode版本中,当您创建了一个新的Swift Cocoa项目时,Xcode将为新的OS X项目生成一个main.swift文件,如下所示:
import Cocoa NSApplicationMain(Process.argc,Process.unsafeArgv)
那是主要的入口点.现在Xcode并不打扰生成这个文件;相反,它只是使用@NSApplicationMain标记您的应用程序委托,并且这个引导步骤在幕后处理.
The Swift Programming Language更多信息:
Apply this attribute to a class to indicate that it is the application delegate. Using this attribute is equivalent to calling the
NSApplicationMain
function and passing this class’s name as the name of the delegate class.If you do not use this attribute,supply a
main.swift
file with amain
function that calls theNSApplicationMain
function. For example,if your app uses a custom subclass ofNSApplication
as its principal class,call theNSApplicationMain
function instead of using this attribute.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。