RxSwift 数据绑定与解绑
2019-04-12 本文已影响0人
屈涯
订阅
//第1次订阅
self.model.userName.asObservable().subscribe {
print("第1次订阅:", $0)
}.disposed(by: disposeBag)
//修改value值
self.model.userName.value = "333"
//第2次订阅
self.model.userSex.asObservable().subscribe {
print("第2次订阅:", $0)
}.disposed(by: disposeBag)
//修改value值
self.model.userSex.value = "444"
取消订阅
var disposeBag = DisposeBag()
let disBag = DisposeBag()
viewModel.disposeBag = disBag