所以我试图理解通用协议和类:
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)
...
}
我是从另一个通用类开始的:
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 ...
}
据我所知,我正在尝试初始化符合通用协议的类型,该协议工作得很好,但View的类型必须与我尝试在{{{{{{{{{{{{{{ 1}}。
然后我尝试用具体视图初始化它,改变attachView(:)
:
init
在init(dispatcher: Dispatcher, view: View, state: @escaping (_ state: AppState)->(ListState<Dispatcher.SW>)) {
self.view = view
...
}
:
AbstractListViewController
得到这个臭名昭着的错误:
presenter = Presenter(dispatcher: dispatcher, view: self, state: state)
这里有相关游乐场的要点:
Non-nominal type 'Presenter' does not support explicit initialization
)https://gist.github.com/nikans/0fde838846ffa9ff2da48c923f850625 请注意,每个空协议实际上都是通用协议,我刚刚删除了不必要的细节。
我想明白:
感谢。
答案 0 :(得分:3)
因此,在Xcode9(测试版6)中,似乎Non-nominal type '%type' does not support explicit initialization
之类的错误只是等于错误较少的Xcode中的mismatching types
错误(如果这样做的话):cannot invoke initializer for type '%type' with an argument list of type '...' expected an argument list of type '...'