首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >不能将不可变值作为inout参数传递:“CGLayerGetContext”是一个函数

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

Stack Overflow用户
提问于 2019-06-13 03:57:57
回答 1查看 58关注 0票数 0

我有下面的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.
        }
    }
}

我该如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-13 04:05:25

请仔细阅读来自苹果的代码,您必须创建上下文

private var playerItemContext = 0

并使用属性,而不是类型

guard context == &playerItemContext else { 

CGLayerGetContext与代码一点关系都没有

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56569556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档