Skip to content

Instantly share code, notes, and snippets.

@nikans
Created September 7, 2017 02:14
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/0fde838846ffa9ff2da48c923f850625 to your computer and use it in GitHub Desktop.
Save nikans/0fde838846ffa9ff2da48c923f850625 to your computer and use it in GitHub Desktop.
Initializing Presenter(dispatcher: dispatcher) successfully, still, cannot call attachView(:)
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