I'm trying to implement a UIViewController extensions that gets the first child view controller with a certain type.
I tried:
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
}
And:
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
}
And this (partially derived from 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
}
Nothing works! How can I do this? Thanks!