3. RxSwift 綁定 bind、bindTo、Binder


bind

let ob = Observable<Int>.interval(1, scheduler: MainScheduler.asyncInstance)

ob.map {
// 對值進一步處理然后返回
    "count " + "\($0)"
}
.bind { text in
    countLab.text = text
}.disposed(by: disposeBag)

ob.bind { x in
    print(x)
}.disposed(by: disposeBag)

Binder + bindTo

let ob = Observable<Int>.interval(1, scheduler: MainScheduler.asyncInstance)
let observer: Binder<String> = Binder(countLab) { lab, text in
    lab.text = text
}

ob.map {
    "c" + "\($0)"
}
.bind(to: observer)
.disposed(by: disposeBag)

搬遷自本人簡書


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM