Q:

KVO AVPlayer.status in Swift

I need to observe AVPlayer.status change.  
I have an AVPlayer instance and a context variable
private var lastPlayer : AVPlayer? 
private var playerStatusContext = 0

After I've set up the AVPlayer instance I add an observer like so:
//  KVO status property
self.lastPlayer!.addObserver(self, forKeyPath: "status", options: [.new, .initial], context: &playerStatusContext)

Then I've overridden observeValue function like so:
override func observeValue(forKeyPath keyPath: String?,  of object: Any?,  change: [NSKeyValueChangeKey : Any]?,  context: UnsafeMutableRawPointer?) 
{
    let status : AVPlayerStatus?  = change?[.newKey] as?  AVPlayerStatus
    if(status ! = nil && context == &playerStatusContext)
    {
        //  DO MY STUFF
    }
}

The problem is that change is either 0 key/value dictionary or some (whatever that means) and my local status constant is always nil, hense I can't do my stuff.  
Maybe I am converting change to AVPlayerStatus wrongly?  Please help.  Thanks. 

A:

Well, it seems like cast like this
let status : AVPlayerStatus?  = change?[.newKey] as?  AVPlayerStatus

does not work.  The app crashed when tried checking change for nil and then force unwrap it.  Using raw values helped:
override func observeValue(forKeyPath keyPath: String?,  of object: Any?,  change: [NSKeyValueChangeKey : Any]?,  context: UnsafeMutableRawPointer?) 
{
    //  Check status
    if keyPath == "status" && context == &playerStatusContext && change ! = nil
    {
        let status = change![.newKey] as!  Int
        //  Status is not unknown
        if(status ! = AVPlayerStatus.unknown.rawValue)
        {
            //  DO STUFF!!! 
        }
    }
}

I am not sure this is the best way however.