I am trying to make a function that, by given a UIView, it iterates recursively to all the subviews until it finds a UIView of type T. So far I have:
func getType(from view: UIView) -> AdaptiveContainerView? {
for aView in view.subviews {
if let adapView = aView as? AdaptiveContainerView {
return adapView
}
else {
return getType(from: aView)
}
}
return nil
}
Now I am trying to refractor the function so it gets the UIView type and returns it if found. By UIView type I mean:
class MyView: UIView {}
My first approach is
func getGenericType<T, Q:UIView>(from view: UIView, ofType: T) -> Q? {
for aView in view.subviews {
if aView is ofType {
}
...
}
return nil
}
However I am having the following error:
Use of undeclared type 'ofType'
Any ideas?
Thank you