无法将'AVPlayer'类型的值转换为'Swift.AnyObject.Type'

时间:2017-07-12 07:51:46

标签: swift xcode

我正在使用swift 3,代码编译,但是当我执行它时,在信号SIGABRT的第一行中断,并给出了错误消息:

if (object as AnyObject).isKind(of: AVPlayer() as Any as! AnyClass) {
        switch keyPath {
            case "status":
                if let value = change[NSKeyValueChangeKey.newKey] as? Int, let itemStatus = AVPlayerItemStatus(rawValue: value) {
                    if itemStatus == .readyToPlay {
                        status = .playing
                        notifyOnPlayBegins()
                    } else if itemStatus == .failed {
                        let error = player?.currentItem?.error
                        print("AVPlayerItem status: \(itemStatus)\nError: \(error)")
                        status = .stopped
                        notifyError(error as! NSError)
                    }
                }
            break

AVPlayer:

open class AVPlayer : NSObject

2 个答案:

答案 0 :(得分:0)

Check it out it will help you.

You can check the object type by three ways:

let object:Any?
object = AVPlayer()

if let player = object as? AVPlayer {
    print("true")
}
if (object!).isKind(of: AVPlayer.self) {
    print("true")
}
if object is AVPlayer {
    print("true")
}

答案 1 :(得分:0)

sudo /path_to_your_version_of_pip/pip install