解决方法
当然可以.
这个特殊的文件叫做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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。