So, I am trying to understand common protocols and classes:
protocol ListPresenterType where View.PDO.SW == Dispatcher.SW { associatedtype Dispatcher: ListDispatcherType associatedtype View: ListViewType init(dispatcher: Dispatcher, state: @escaping (_ state: AppState)->(ListState<Dispatcher.SW>)) func attachView(_ view: View) ... }
And I initiate it from another generic class:
class AbstractListViewController<Presenter: ListPresenterType, PDO: ListPDOCommonType, ...>: ListViewType, ... where PDO.SW == Presenter.Dispatcher.SW, ... { func configure(withBla: bla) { ... presenter = Presenter(dispatcher: dispatcher, state: state) } func someFunc() { presenter.attachView(self)
As I understand it, I am trying to initialize a type that conforms to the standard protocol, which works fine, but the view type must not be compatible with what I am trying to pass to attachView(:) .
Then I try to initialize it with a specific view, changing init :
init(dispatcher: Dispatcher, view: View, state: @escaping (_ state: AppState)->(ListState<Dispatcher.SW>)) { self.view = view ... }
And in AbstractListViewController :
presenter = Presenter(dispatcher: dispatcher, view: self, state: state)
And get this shameful mistake:
Non-nominal type 'Presenter' does not support explicit initialization
Here are the relevant playgrounds:
Note that each empty protocol is actually a common protocol, I just deleted the unnecessary data.
I would like to understand:
- What makes the "nominal" type "non-nominal" all of a sudden (there is nothing to be surprised at, it is a common parameter that matches the general protocol, but I donβt understand causality).
- I heard something about erasing styles, but didn't quite understand if it is applicable here.
Thanks.