Swift中的通用MVP实现

时间:2017-12-22 08:51:17

标签: swift generics swift4

我们的想法是使用基本协议和类来实现MVP结构,这些类包含对通用视图和演示者的引用

// --- Base --- //
protocol BaseViewProtocol: class {
    associatedtype P: BasePresenterProtocol
    var presenter: P? { get set }
}
class BaseView<P: BasePresenterProtocol>: UIView, BaseViewProtocol {
    var presenter: P?
}

protocol BasePresenterProtocol {
    associatedtype V: BaseViewProtocol
    weak var view: V? { get set }
}
class BasePresenter<V: BaseViewProtocol>: BasePresenterProtocol {
    weak var view: V?
}

// --- Current --- //
protocol CurrentViewProtocol: BaseViewProtocol {
}
class CurrentView<P: CurrentPresenterProtocol>: BaseView<P>, CurrentViewProtocol {
}

protocol CurrentPresenterProtocol: BasePresenterProtocol {
}
class CurrentPresenter<V: CurrentViewProtocol>: BasePresenter<V>, CurrentPresenterProtocol {
    init(currentView: V) {
        super.init()
        self.view = currentView
    }
}

问题是如何实例化所有这些类的具体实现,因为View和Presenter都是泛型类并且彼此依赖

1 个答案:

答案 0 :(得分:1)

不确定这是最好的方式,但我以这种方式做了类似的事情

Error : .onLoad nie powiodło się w funkcji 'loadNamespace()' dla pakietu 'rJava', szczegóły:
  wywołanie: fun(libname, pkgname)
  błąd:  No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.
In addition: Warning messages:
1: pakiet ‘xlsx’ został zbudowany w wersji R 3.3.2 
2: pakiet ‘rJava’ został zbudowany w wersji R 3.3.3 
Error: pakiet ‘rJava’ nie mógł zostać załadowany
相关问题