我正在尝试使用 Swift 5 运行 Apple 的示例 DemoBots ( https://developer.apple.com/library/archive/samplecode/DemoBots/Introduction/Intro.html#//apple_ref/doc/uid/TP40015179 ) 项目,但该应用程序无法加载 Logo 启动页面。
我已经更新了项目中所有 Swift3 已弃用的方法/属性,例如将 SceneMetadata 类中过时的 hashValue 属性更改为 hash(into hasher: inout Hasher)、将 isAsynchronous 添加到 SceneOperation 类等。
如果有人在使用 Swift5 运行 DemoBots 时遇到类似问题,请告诉我您是如何解决的。
这是我的场景操作代码:
class SceneOperation: Operation {
// MARK: Types
/**
Using the `@objc` prefix exposes this enum to the ObjC runtime,
allowing the use of `dynamic` on the `state` property.
*/
@objc enum State: Int {
/// The `Operation` is ready to begin execution.
case ready
/// The `Operation` is executing.
case executing
/// The `Operation` has finished executing.
case finished
/// The `Operation` has been cancelled.
case cancelled
}
// MARK: Properties
/// Marking `state` as dynamic allows this property to be key-value observed.
@objc dynamic var state = State.ready
// MARK: NSOperation
override var isReady: Bool {
return state == .ready && super.isReady
}
override var isExecuting: Bool {
return state == .executing
}
override var isFinished: Bool {
return state == .finished
}
override var isCancelled: Bool {
return state == .cancelled
}
override var isAsynchronous: Bool {
return true
}
/**
Add the "state" key to the key value observable properties of `NSOperation`.
*/
dynamic class func keyPathsForValuesAffectingIsReady() -> Set<String> {
return ["state"]
}
dynamic class func keyPathsForValuesAffectingIsExecuting() -> Set<String> {
return ["state"]
}
dynamic class func keyPathsForValuesAffectingIsFinished() -> Set<String> {
return ["state"]
}
dynamic class func keyPathsForValuesAffectingIsCancelled() -> Set<String> {
return ["state"]
}
}
应用程序成功构建,没有运行时或编译时错误/警告。但它只显示了 DemoBots Logo 和背景中的绿色粒子动画。没有渲染任何菜单或关卡场景。
最佳答案
很可能,在将项目转换为最新版本的 Swift 时,您选择禁用 @objc
接口(interface)。不幸的是,如果没有这个,该项目将无法进行。您可以尝试在build设置中打开 Swift 3 @objc Inference
。
或者在这里您可以获得支持 Swift 5 的 DemoBot 版本: https://github.com/iTehdrew/DemoBot
关于ios - Apple DemoBats 项目停止在 Swift 5 的登陆页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56548412/