gpt4 book ai didi

ios - 快速检查类是否具有封装协议(protocol)

转载 作者:行者123 更新时间:2023-11-30 13:44:11 25 4
gpt4 key购买 nike

如何检查一个类是否符合封装协议(protocol)?

协议(protocol):

@objc protocol Animation {
func updateWithState (state: GKState)
}

类(class):

class car : Entity, Animation {
}

某处:

 if let myVC = entity as? Animation {
myVC.updateWithState(nextState)
}

工作正常。

<小时/>

虽然......

协议(protocol):

@objc protocol Vehicle:  Animation {}

类(class):

class car : Entity, Vehicle {
}

某处:

 if let myVC = entity as? Animation {
myVC.updateWithState(nextState)
}

不起作用,总是 False,从不进入内部。

如何查看协议(protocol)内的协议(protocol)?

坦克!

最佳答案

通过 Playground 进行检查,它可以使用纯 Swift 正常工作,因此如果它不适合您,那么可能与 @objc 桥接有关,请参阅下图以了解工作 Playground 。

enter image description here

关于ios - 快速检查类是否具有封装协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35184592/

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