@main 特性

版本新特性 / Swift 5.3

// *** 以前 ***
// 入口点是名为 main.swift 的文件,其中是顶层代码,
// 而该文件遵循自己的一套规则
// main.swift:
//     let tool = Tool()
//     tool.run()

// 应用改为标记它的代理
// @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { }

// *** 在 5.3 版本中 ***
@main
struct Tool {
    static func main() {
        print("started")
    }
}

// 该类型可以是结构体、类或枚举,main() 可以抛出错误;
// 模块中恰好有一个类型带有该特性,旁边不能再有 main.swift。
// @UIApplicationMain 和 @NSApplicationMain 成了它的特例