extension UIViewController {
func getChildViewController<T>(OfType: T) {
let classType = Mirror(reflecting: self.childViewControllers.first).subjectType
if classType == T.self {
print("there is a match")
}
}
}
此视图控制器的类型比较是一个扩展的UIViewController,当你调用这个函数,你通过它例如类型:在迅速
ViewController.getChildViewController(OfType: SecondViewController.self)
这将检查的第一个孩子视图控制器如果类型SecondViewController的
但是在if语句,我得到的错误:
Binary operator '==' cannot be applied to operands of type 'Any.Type' and 'T'
我莫名其妙地成功斯威夫特编译这3 – Sweeper