gpt4 book ai didi

ios - 无法将不可变值作为 inout 参数传递 : 'CGLayerGetContext' is a function

转载 作者:行者123 更新时间:2023-11-29 05:40:53 27 4
gpt4 key购买 nike

我有以下内容code from apple 。我收到此错误:

Cannot pass immutable value as inout argument: 'CGLayerGetContext' is a function

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.
}
}
}

如何解决这个问题?

最佳答案

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

private var playerItemContext = 0

并使用属性,而不是类型

guard context == &playerItemContext else { 

CGLayerGetContext与代码完全无关

关于ios - 无法将不可变值作为 inout 参数传递 : 'CGLayerGetContext' is a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56569556/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com