当我运行以下代码(一个简化的示例,为了演示崩溃而创建)时,当我选择“运行”时,它会按预期执行(两条 os_log 消息都在控制台中打印)。
但是,当我从内存调试导航器中的仪器中打开它时 - 通过按“重新启动” - 它崩溃了(仅在控制台中打印第一个 os_log 消息)。
崩溃发生在observe(...)处。
import os
import UIKit
class ObserverCrashingExample: NSObject {
@objc private var animation: UIViewPropertyAnimator?
private var observer: NSKeyValueObservation?
override init() {
super.init()
animation = UIViewPropertyAnimator( duration: 1, curve: .linear, animations: { })
animation!.pauseAnimation()
os_log("X_AMPLE Executes")
observer = animation!.observe(\.isRunning, options: [.new, .old]) { _ , _ in }
os_log("X_AMPLE Does not execute")
}
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
}
我正在运行 Xcode 9.3、Swift 4.1、iOS 11.3 部署目标。
有任何想法吗?这是编译器问题吗?
Cheers
我尝试了三个单词:
- 禁用“记录引用计数”。这阻止了它崩溃。但仪器显示出比平常更多的泄漏,这使得定位真正的泄漏变得不可能。
- 评论我所有的 KVO 调用。在我的情况下不起作用。
- 将我的代码降级到 Swift 4.0。我重新安装了 Xcode 9.2,现在可以使用了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)