Skip to content

Instantly share code, notes, and snippets.

@nikans
Created September 7, 2017 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikans/53c3ea146ceb12dc8461f7ba8a81793d to your computer and use it in GitHub Desktop.
Save nikans/53c3ea146ceb12dc8461f7ba8a81793d to your computer and use it in GitHub Desktop.
Cannot initialize Presenter(dispatcher: dispatcher, view: self)
import UIKit
protocol ListPDOCommonType {
}
protocol ListDispatcherType {
init()
}
protocol ListViewType: class {
associatedtype PDO: ListPDOCommonType
func setList(_ list: PDO?)
}
protocol ListPresenterType {
associatedtype Dispatcher: ListDispatcherType
associatedtype View: ListViewType
init(dispatcher: Dispatcher, view: View)
func attachView(_ view: View)
}
class ListPresenter<Dispatcher: ListDispatcherType, View: ListViewType>: ListPresenterType {
internal let dispatcher: Dispatcher
weak internal var view : View?
required init(dispatcher: Dispatcher, view: View) {
self.view = view
self.dispatcher = dispatcher
}
func attachView(_ view: View) {
self.view = view
}
}
class AbstractListViewController<Presenter: ListPresenterType, PDO: ListPDOCommonType>
: UIViewController, ListViewType
where Presenter.View.PDO == PDO {
typealias Dispatcher = Presenter.Dispatcher
fileprivate var dispatcher: Dispatcher!
fileprivate var presenter: Presenter!
func configure() {
dispatcher = Dispatcher()
presenter = Presenter(dispatcher: dispatcher, view: self)
}
override func viewWillAppear(_ animated: Bool) {
presenter.attachView(self)
}
func setList(_ list: PDO?) {
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment