I'm trying to write a simple MVP pattern to follow in my app, so I've written two porotocols to define View Controller and Presenters:
protocol PresenterType: class { associatedtype ViewController: ViewControllerType var viewController: ViewController? { get set } func bind(viewController: ViewController?) } protocol ViewControllerType: class { associatedtype Presenter: PresenterType var presenter: Presenter { get } init(presenter: Presenter) } After having those defined I started writing some RootViewController and RootViewPresenter. The latter looks like:
protocol RootViewControllerType: ViewControllerType { } final class RootPresenter<VC: RootViewControllerType>: PresenterType { weak var viewController: VC? func bind(viewController: VC?) { self.viewController = viewController } } Up to this point everything complies and is fine, but when I start implementing View Controller like this:
protocol RootPresenterType: PresenterType { } final class RootViewController<P: RootPresenterType>: UIViewController, ViewControllerType { let presenter: P init(presenter: Presenter) { self.presenter = presenter super.init(nibName: nil, bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() presenter.bind(viewController: self) } } Immediately I get the following error message:
Cannot convert value of type 'RootViewController
' to expected argument type '_?'
I know that protocols with associated types can introduce some limitations, but this example is pretty straightforward and I can't make it work. Is it possible to achieve something that I want, or do I have to look for some other, less Swifty pattern?

