Observing property crashes Instruments (Leaks profile) Xcode 9.3 (Swift 4.1)

て烟熏妆下的殇ゞ 提交于 2019-12-10 05:48:06

问题


When I run the following code (a simplified example, created to demonstrate the crash), it executes as expected when I choose Run (both os_log messages print in Console).

However, when I open it in Instruments from the Memory Debug Navigator - by pressing Restart - it crashes (only the first os_log message prints in Console).

The crash occurs at 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") }

}

I am running Xcode 9.3, Swift 4.1, iOS 11.3 deployment target.

Any ideas? Is this a compiler issue?

Cheers


回答1:


I tried three word-arounds:

  1. Disabling "Record Reference Count". This stopped it from crashing. But the instruments showed me much more leaks than usual, which makes locating real leaks impossible.
  2. Commenting all my KVO calls. Didn't work in my case.
  3. Downgrading my code to Swift 4.0. I re-installed Xcode 9.2, and it works now.


来源:https://stackoverflow.com/questions/49729233/observing-property-crashes-instruments-leaks-profile-xcode-9-3-swift-4-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!