如何检查两个UIViewController子类对象是否具有相同的子类?
答案 0 :(得分:2)
在Swift 3中,您可以使用类型(of:)方法比较对象的类型:
class VC1: UIViewController {
}
class VC2: UIViewController {
}
let vc1 = VC1()
let vc2 = VC2()
let typeComparisonResult = type(of: vc1) == type(of: vc2)
答案 1 :(得分:0)
Swift允许使用is
关键字进行类比较。例如,如果class a
和class b
都是UIViewController的子类。然后,您可以使用is关键字确认这一点。
class a:UIViewController
{
}
class b:UIViewController
{
}
let instanceA:a = a()
let instanceB:b = b()
if a is UIViewController && b is UIViewController
{
print("Both are subclasses of UIViewController")
}