我第一次问问题,我正在学习RxSwift,如何使用bind to和driver,driver和bind to有什么区别。现在还有谁在学习RxSwift。如果你正在学习RxSwift或Swift或OC ,我希望我们能成为朋友,互相学习。
@iwillnot 回复很好,但我会尝试用一个例子来改进它:
想象一下你有这样的代码:
let intObservable = sequenceOf(1, 2, 3, 4, 5, 6)
.observeOn(MainScheduler.sharedInstance)
.catchErrorJustReturn(1)
.map { $0 + 1 }
.filter { $0 < 5 }
.shareReplay(1)
正如@iwillnot 所写:
Driver您可以从文档中详细了解驱动程序的全部内容。总之,它只是允许您依赖这些属性:
- 不能出错
- 观察主调度程序
- 分享副作用
如果你使用Driver
,您不必指定observeOn
, shareReplay
nor catchErrorJustReturn
.
总之,上面的代码与使用以下代码类似Driver
:
let intDriver = sequenceOf(1, 2, 3, 4, 5, 6)
.asDriver(onErrorJustReturn: 1)
.map { $0 + 1 }
.filter { $0 < 5 }
更多细节 https://github.com/ReactiveX/RxSwift/issues/275
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)