gpt4 book ai didi

ios11 - NSUnknownKeyException : was sent to an object that is not KVC-compliant for the "player" property

转载 作者:行者123 更新时间:2023-12-04 13:18:32 26 4
gpt4 key购买 nike

我已将代码更新为在Xcode 9中快速运行4。在此之前,它可以正常工作。但是现在AVplayer崩溃了,下面是崩溃的代码。

addObserver(self, forKeyPath: "player.currentItem.duration", options: [.new, .initial], context: &playerViewControllerKVOContext)

日志是

Terminating app due to uncaught exception 'NSUnknownKeyException',reason: '[ addObserver: forKeyPath:@"player.currentItem.duration" options:5 context:0x10ff74ac8] was sent to an object that is not KVC-compliant for the "player" property.'

最佳答案

Swift没有自己的键值观察器,因此对于Swift 4,我们必须添加:
@objc dynamic
在您需要观察其值的属性之前。在您的情况下,它将是AVPlayer实例。例如。:

class MyPlayerCustomView: UIView {

@objc dynamic var myPlayer: AVPlayer?

}

希望这能解决您的问题。它确实解决了我的问题!

关于ios11 - NSUnknownKeyException : was sent to an object that is not KVC-compliant for the "player" property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46419893/

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