Swift generics: Non-nominal type does not support explicit initialization

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) // ERROR: Cannot invoke 'attachView' with an argument list of type ... } 

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.

+3
source share
1 answer

Thus, it seems that in Xcode9 (beta 6) errors, such as Non-nominal type '%type' does not support explicit initialization , are simply equal to the mismatching types error with a smaller Xcode buggy (if it's something): cannot invoke initializer for type '%type' with an argument list of type '...' expected an argument list of type '...'

+3
source

Source: https://habr.com/ru/post/1272179/


All Articles