【问题标题】:Cannot pass immutable value as inout argument: 'CGLayerGetContext' is a function无法将不可变值作为 inout 参数传递:“CGLayerGetContext”是一个函数
【发布时间】:2019-06-12 19:57:57
【问题描述】:

我有下面的code from apple。我收到此错误:

不能将不可变值作为 inout 参数传递:'CGLayerGetContext' 是一个函数

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    // Only handle observations for the playerItemContext
    guard context == &CGLayerGetContext else { //error here
        super.observeValue(forKeyPath: keyPath, of: object,change: change, context: context)
        return
    }

    if keyPath == #keyPath(AVPlayerItem.status) {
        let status: AVPlayerItem.Status

        // Get the status change from the change dictionary
        if let statusNumber = change?[.newKey] as? NSNumber {
            status = AVPlayerItem.Status(rawValue: statusNumber.intValue)!
        } else {
            status = .unknown
        }

        // Switch over the status
        switch status {
        case .readyToPlay: break
        // Player item is ready to play.
        case .failed: break
        // Player item failed. See error.
        case .unknown: break
            // Player item is not yet ready.
        }
    }
}

我该如何解决这个问题?

【问题讨论】:

  • 苹果代码中没有CGLayerGetContext

标签: ios swift


【解决方案1】:

请仔细阅读 apple 的代码,你必须创建上下文

private var playerItemContext = 0

并使用属性,而不是类型

guard context == &playerItemContext else { 

CGLayerGetContext与代码完全无关

【讨论】:

    猜你喜欢
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    相关资源
    最近更新 更多