繁体   English   中英

观察属性崩溃仪器(泄漏配置文件)Xcode 9.3(Swift 4.1)

[英]Observing property crashes Instruments (Leaks profile) 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部署目标。

有任何想法吗? 这是编译器问题吗?

干杯

我尝试了三个单词:

  1. 禁用“记录引用计数”。 这阻止了它崩溃。 但仪器显示出比平时更多的泄漏,这使得找到真正的泄漏是不可能的。
  2. 评论我所有的KVO电话。 在我的情况下不起作用。
  3. 将我的代码降级为Swift 4.0。 我重新安装了Xcode 9.2,现在可以使用了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM