TL;DR
I'm looking for an array type (var array = [TheTypeImLookingFor]()
) like 'all objects that subclasses UIViewController
and implements the protocol MyProtocol
.
Explanation
I'm building a kind of wizard view with a container view and embedded child views (controller). No problem, this will work as long, as I have only one base
type of child view controllers.
Due to the content of screens, I have now a bunch of view controllers of type MyTableViewController
which is a subclass of UITableViewController
and other view controllers that have regular UIViewControllers
as base.
All of the view controllers have one thing in common. A default data property myData: MyObject
.
I created a protocol MyProtocol
that contains this property.
Now, I have to combine all this view controllers into one array to use it as wizard steps. As long as I only have to access the view controller methods (array items are type of UIViewController
) I'm able to use var viewControllers = [UIViewController]()
or if I wanna only access the myData
property, I change the array item type to MyObject
.
But the problem is, I have to access the methods from the UIViewController
and from the protocol.
That's why I'm looking for an array type like 'all objects that subclasses UIViewController
and implements the protocol MyProtocol
.
I tried:
var viewControllers = [UIViewController: MyProtocol]()
// is a dict- `var viewControllers = UIViewController where MyProtocol
- `var viewControllers = UIViewController.conforms(to: MyProtocol)
- ...
But nothing works as expected.