我有吼叫声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.
}
}
}
我该如何解决?
答案 0 :(得分:1)
请仔细阅读来自Apple的代码,您必须创建上下文
// Calculate the adjustment
let value = (window_position + window_height - (height / 2) - (window_height / 2)) * item.options.speed;
// If the element is not fixed then adjust the algorithm
if (!item.options.fixed) {
value += (top * -1 * item.options.speed);
}
value = Math.round(value);
并使用属性,而不是类型
private var playerItemContext = 0
和guard context == &playerItemContext else {
与代码完全无关