作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下内容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/
我有以下内容code from apple 。我收到此错误: Cannot pass immutable value as inout argument: 'CGLayerGetContext' is
我是一名优秀的程序员,十分优秀!