Xcode 8 Beta 6:main.swift无法编译 [英] Xcode 8 beta 6: main.swift won't compile
问题描述
我们有一个自定义的UIApplication对象,所以我们的main.swift是
We have a custom UIApplication object, so our main.swift was
import Foundation
import UIKit
UIApplicationMain(Process.argc, Process.unsafeArgv, NSStringFromClass(MobileUIApplication), NSStringFromClass(AppDelegate))
并且在Xcode 8 beta 5中不起作用,因此我们使用了
and that didn't work in Xcode 8 beta 5 so we used this
//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'
On Xcode 8 beta 6 we get Use of unresolved identifier 'Process'
我们需要在Xcode 8 beta 6/Swift 3中定义UIApplicationMain吗?
What do we need to do in Xcode 8 beta 6/Swift 3 to define the 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
.
To change the UIApplication class, substitute NSStringFromClass(MobileUIApplication.self)
for nil
in that formulation.
但是,如果您的 only 目的是将UIApplication子类替换为共享应用程序实例,则有一种更简单的方法:在 Info.plist 中,添加"主体类"键,并将其值设置为UIApplication子类的字符串名称,并使用@objc(...)
属性为该子类的声明进行标记,并为其赋予相同的Objective-C名称.
However, if your only purpose here is to substitute a UIApplication subclass as the shared application instance, there's an easier way: in the Info.plist, add the "Principal class" key and set its value to the string name of your UIApplication subclass, and mark your declaration of that subclass with an @objc(...)
attribute giving it the same Objective-C name.
编辑现在,此问题已在Swift 4.2中解决. CommandLine.unsafeArgv
现在具有正确的签名,并且可以轻松调用UIApplicationMain
:
EDIT This problem is now solved in Swift 4.2. CommandLine.unsafeArgv
now has the correct signature, and one can call UIApplicationMain
easily:
UIApplicationMain(
CommandLine.argc, CommandLine.unsafeArgv,
nil, NSStringFromClass(AppDelegate.self)
)
这篇关于Xcode 8 Beta 6:main.swift无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!