我正在学习Viper
w/ RxSwift
。
我想通知我在我Presenter
的.viewDidLoad
ViewController
为此,我有以下内容:
class LoginPresenter {
weak var view: LoginView?
var interactor: LoginUseCase?
var router: LoginRouter?
private(set) var viewDidLoad = PublishSubject<Void>()
private lazy var disposeBag = DisposeBag()
required init(view: LoginView?, interactor: LoginUseCase?, router: LoginRouter?) {
self.view = view
self.interactor = interactor
self.router = router
viewDidLoad
.subscribe(onNext: { _ in
// do something on viewDidLoad
}).disposed(by: disposeBag)
}
}
class LoginViewController: UIViewController {
var presenter: LoginPresenter?
override func viewDidLoad() {
super.viewDidLoad()
presenter?.viewDidLoad.onNext(())
}
}
加载视图后,我正在调用presenter?.viewDidLoad.onNext(())
然后我可以在我的演示者中触发任何操作,例如调用 myrouter
以确保配置导航或我的interactor
.
我应该PublishSubject
为此使用 a 吗?还是RxSwift
有更适合的类型?
我觉得这种方法意味着我最终会得到类似的东西
viewDidLoad
.subscribe(onNext: { _ in
self.router?.viewDidLoad.onNext(())
}).disposed(by: disposeBag)