观察属性崩溃仪器(泄漏配置文件)Xcode 9.3(Swift 4.1)
当我运行以下代码(一个简化示例,为演示崩溃而创建)时,它会在我选择Run时按预期执行(两个os_log消息都在Console中打印)。
但是,当我从Memory Debug Navigator中打开它时 – 通过按下Restart – 它会崩溃(只有第一个os_log消息在Console中打印)。
崩溃发生在观察(…)。
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部署目标。
有任何想法吗? 这是编译器问题吗?
干杯
我尝试了三个单词:
- 禁用“记录引用计数”。 这阻止了它崩溃。 但仪器显示出比平常更多的泄漏,这使得找到真正的泄漏是不可能的。
- 评论我所有的KVO电话。 在我的情况下不起作用。
- 将我的代码降级为Swift 4.0。 我重新安装了Xcode 9.2,现在可以使用了。