As it mentioned in the 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."
So, basically, it's a way of getting your app bootstrapped and running without having to write some global-level boilerplate in a separate Swift file. In previous versions of Xcode, when you created a new Swift Cocoa project, Xcode would generate a main.swift
file for a new OS X project that looked like this:
import Cocoa
NSApplicationMain(Process.argc, Process.unsafeArgv)
And that was the main entry point. Now Xcode doesn't bother generating this file; instead it just tags your app delegate with @NSApplicationMain
and this bootstrapping step is handled behind the scenes.
More info from 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 a main
function that calls the NSApplicationMain
function. For example, if your app uses a custom subclass of NSApplication
as its principal class, call the NSApplicationMain
function instead of using this attribute.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…