Shu*_*Din 6 kvc swift4 ios11 xcode9
我已将代码更新为Xcode 9中的swift 4.在此之前它运行正常.但现在AVplayer在下面的观察者身上崩溃的是崩溃的代码.
addObserver(self, forKeyPath: "player.currentItem.duration", options: [.new, .initial], context: &playerViewControllerKVOContext)
Run Code Online (Sandbox Code Playgroud)
而日志是
因未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[addObserver:forKeyPath:@"player.currentItem.duration"options:5 context:0x10ff74ac8]被发送到与"player"属性不符合KVC的对象".
Jun*_*tar 16
Swift没有自己的Key值观察器,因此对于swift 4我们必须添加:
@objc动态
在您需要观察其价值的财产之前.在您的情况下,它将是AVPlayer实例.例如:
class MyPlayerCustomView: UIView {
@objc dynamic var myPlayer: AVPlayer?
}
Run Code Online (Sandbox Code Playgroud)
希望这能解决你的问题.它解决了我的问题!
| 归档时间: |
|
| 查看次数: |
2018 次 |
| 最近记录: |