我们有一个自定义的UIApplication对象,所以我们的main.swift是
import Foundation import UIKit UIApplicationMain(Process.argc, Process.unsafeArgv, NSStringFromClass(MobileUIApplication), NSStringFromClass(AppDelegate))
并且在Xcode 8 beta 5中不起作用,所以我们使用了这个
//TODO Swift 3 workaround? https://forums.developer.apple.com/thread/46405 UIApplicationMain( Process.argc, UnsafeMutablePointer<UnsafeMutablePointer<CChar>>(Process.unsafeArgv), nil, NSStringFromClass(AppDelegate.self))
在Xcode 8 beta 6上,我们获得了 使用未解析的标识符’Process’
我们需要在Xcode 8 beta 6 / Swift 3中做什么来定义UIApplicationMain?
我这样写:
UIApplicationMain( CommandLine.argc, UnsafeMutableRawPointer(CommandLine.unsafeArgv) .bindMemory( to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)), nil, NSStringFromClass(AppDelegate.self) )
要改变UIApplication类,替代NSStringFromClass(MobileUIApplication.self)了nil该配方。
NSStringFromClass(MobileUIApplication.self)
nil
但是,如果您的 唯一 目的是将UIApplication子类替换为共享应用程序实例,则有一种更简单的方法:在 Info.plist中 ,添加“ Principal class”键并将其值设置为UIApplication子类的字符串名称,并使用@objc(...)赋予该对象相同的Objective- C名称的属性标记该子类的声明。
@objc(...)
编辑 现在,在Swift 4.2中解决了此问题。CommandLine.unsafeArgv现在具有正确的签名,并且可以UIApplicationMain轻松拨打电话:
CommandLine.unsafeArgv
UIApplicationMain
UIApplicationMain( CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self) )