I am having trouble with the new observe
API in Swift 4.
player = AVPlayer()
player?.observe(\.currentItem.status, options: [.new], changeHandler: { [weak self] (player, newValue) in
if let status = AVPlayer.Status(rawValue: (newValue as! NSNumber).intValue) {
}
}
But I get an error
Type of expression is ambiguous without more context.
How do I fix it? Not sure about keyPath
syntax.
There is also a warning in extracting AVPlayerStatus in the closure above
Cast from 'NSKeyValueObservedChange' to unrelated type 'NSNumber' always fails"