Xcode使用以下代码创建了AppDelegate.swift
import Cocoa@NSApplicationMainclass 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()在哪里?
解决方法 正如 release notes年所提到的那样: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 CocoaNSApplicationMain(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.
以上是内存溢出为你收集整理的在xcode中的swift编程项目中使用了@NSApplicationMain全部内容,希望文章能够帮你解决在xcode中的swift编程项目中使用了@NSApplicationMain所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)