【发布时间】:2015-01-03 21:56:11
【问题描述】:
我正在尝试实现一个 UIViewController 扩展,以获取具有特定类型的第一个子视图控制器。
我试过了:
func getChildViewController(#type:UIViewController.Type) -> UIViewController? {
for vc:UIViewController in self.childViewControllers as [UIViewController] {
if vc is type { //<-- 'type is not a type'
return vc
}
}
return nil
}
还有:
func getChildViewController(#type:Type) -> UIViewController? { // "Type", doesn't exist
for vc:UIViewController in self.childViewControllers as [UIViewController] {
if vc is type {
return vc
}
}
return nil
}
还有这个(部分来源于How to pass a class type as a function parameter):
func getChildViewController<T>(#type:T.Type) -> UIViewController? {
for vc:UIViewController in self.childViewControllers as [UIViewController] {
if vc is type { //<-- 'type is not a type'
return vc
}
}
return nil
}
没有任何作用!我怎样才能做到这一点?谢谢!
【问题讨论】:
标签: swift