Jas*_*ker 23 xcode program-entry-point swift swift3 xcode8-beta6
我们有一个自定义的UIApplication对象,所以我们的main.swift是
import Foundation
import UIKit
UIApplicationMain(Process.argc, Process.unsafeArgv, NSStringFromClass(MobileUIApplication), NSStringFromClass(AppDelegate))
Run Code Online (Sandbox Code Playgroud)
这在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))
Run Code Online (Sandbox Code Playgroud)
在Xcode 8 beta 6上,我们使用未解析的标识符'Process'
我们需要在Xcode 8 beta 6/Swift 3中做些什么才能定义UIApplicationMain?
mat*_*att 57
我这样写:
UIApplicationMain(
CommandLine.argc,
UnsafeMutableRawPointer(CommandLine.unsafeArgv)
.bindMemory(
to: UnsafeMutablePointer<Int8>.self,
capacity: Int(CommandLine.argc)),
nil,
NSStringFromClass(AppDelegate.self)
)
Run Code Online (Sandbox Code Playgroud)
要改变UIApplication类,替代NSStringFromClass(MobileUIApplication.self)
了nil
该配方.
但是,如果您的唯一目的是将UIApplication子类替换为共享应用程序实例,则有一种更简单的方法:在Info.plist中,添加"Principal class"键并将其值设置为UIApplication子类的字符串名称,并使用@objc(...)
赋予其相同Objective-C名称的属性标记您的子类的声明.
编辑此问题现在在iOS 12/Xcode 10中得到解决.CommandLine.unsafeArgv
现在具有正确的签名,可以UIApplicationMain
轻松调用:
UIApplicationMain(
CommandLine.argc, CommandLine.unsafeArgv,
nil, NSStringFromClass(AppDelegate.self)
)
Run Code Online (Sandbox Code Playgroud)
它似乎Process
已CommandLine
在beta 6中重命名为。
但是的类型与CommandLine.unsafeArgv
的第二个参数不匹配UIApplication
,因此您可能需要编写如下内容:
CommandLine.unsafeArgv.withMemoryRebound(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc)) {argv in
_ = UIApplicationMain(CommandLine.argc, argv, NSStringFromClass(MobileUIApplication.self), NSStringFromClass(AppDelegate.self))
}
Run Code Online (Sandbox Code Playgroud)
(更新)此不匹配应视为错误。通常,您最好在发现“本不应该”的东西时发送错误报告,例如beta 5中的第三个参数。我希望这个“错误”会尽快得到解决。
如果只想指定自定义UIApplication类,为什么不使用Info.plist?
NSPrincipalClass | String | $(PRODUCT_MODULE_NAME).MobileUIApplication
Run Code Online (Sandbox Code Playgroud)
(在“原始键/值”视图中显示为“主体类”。)
在Info.plist中,您可以使用MobileUIApplication
正常方式使用@UIApplicationMain
。
(添加)标头文档UIApplicationMain
:
Run Code Online (Sandbox Code Playgroud)// If nil is specified for principalClassName, the value for NSPrincipalClass from the Info.plist is used. If there is no // NSPrincipalClass key specified, the UIApplication class is used. The delegate class will be instantiated using init.
归档时间: |
|
查看次数: |
6755 次 |
最近记录: |