我想比較的UIViewController在斯威夫特3,但有一些錯誤如何比較Swift 3中的UIViewController?
extension UINavigationController
{
func myPopToViewController(viewController:UIViewController, animated:Bool) -> UIViewController? {
var arrViewControllers:[UIViewController] = []
arrViewControllers = self.viewControllers
for vc:UIViewController in arrViewControllers {
if(vc.isKind(of: viewController)) // This Line gives me error
{
return (self.navigationController?.popToViewController(vc, animated: animated)?.last)!
}
}
return nil
}
}
/Users/varunnaharia/Documents/Projects/appname/appname/Public/UINavigationController+Extra.swift:18:30 :無法將類型的價值 '的UIViewController' 預期參數類型 'AnyClass'(又名 'AnyObject.Type')
,如果嘗試使用
if(vc is viewController)
它給
/Users/varunnaharia/Documents/Projects/appname/appname/Public/UINavigationController+Extra.swift:18:22:使用未聲明的類型 '的viewController'
我通過它調用它
self.navigationController?.popOrPopToViewController(viewController: MyUIViewController(), animated: false)
工作,如果是VC arrViewControllers {}試試這個 –
請解釋它是如何工作的?它是給出相同的錯誤... –
嘗試'如果(vc是UIViewController)' –