参见英文答案 Swift dynamic type checking for structs?2个 Swift 3中的type(of:x)似乎不适用于is类型检查 它只是给出了此错误消息: Consecutive statements on a line must be separated by ‘;’ 代码示例: cla
Swift 3中的type(of:x)似乎不适用于is类型检查
它只是给出了此错误消息:
Consecutive statements on a line must be separated by ‘;’
代码示例:
class Test : UIViewController {} let test = Test() let test2 = Test() let isEqual = test2 is type(of: test) // this does not compile
这有什么不对?
如何在Swift 3中进行这样的动态类型检查?
class Test : UIViewController {} class Test1 : UIViewController {} let test = Test() let test2 = Test1() let f = test2.isKind(of: test2.classForCoder) print(f)
Output: true
这可能是检查类型的另一个想法
除此之外
let q = type(of: test) == type(of: test)
将返回true,但仅当它是同一个类而不是子类时