解决方法
当然可以.
这个特殊的文件叫做main.swift,它的行为就像一个Playground文件.
从Files and Initialization开始,Apple Swift博客上的帖子:
… The “main.swift” file can contain top-level code,and the
order-dependent rules apply as well. In effect,the first line of code
to run in “main.swift” is implicitly defined as the main entrypoint
for the program. This allows the minimal Swift program to be a single
line — as long as that line is in “main.swift”.
但是,在iOS上,@ UapppplicationMain是应用程序入口点.它会自动为您完成整个启动工作.但是在iOS应用程序的main.swift中,您必须手动初始化它.
在Swift 3.1中,你的main.swift文件应该像这样开始:
// main.swift import Foundation import UIKit class AppDelegate: UIResponder,UIApplicationDelegate { var window: UIWindow? } UIApplicationMain( CommandLine.argc,UnsafeMutableRawPointer(CommandLine.unsafeArgv) .bindMemory( to: UnsafeMutablePointer<Int8>.self,capacity: Int(CommandLine.argc)),nil,NSStringFromClass(AppDelegate.self) ) // Your code begins here