I'm the first time to ask a question,I'm learning RxSwift, how to use bind to and driver, what's the difference between of driver and bind to.Anyone else learning RxSwift now.If you are learning RxSwift or Swift or OC,i hope we can be friends and learn from each other.
@iwillnot response is fine but I will try to improve it with an example:
Imagine you have this code:
let intObservable = sequenceOf(1, 2, 3, 4, 5, 6)
.observeOn(MainScheduler.sharedInstance)
.catchErrorJustReturn(1)
.map { $0 + 1 }
.filter { $0 < 5 }
.shareReplay(1)
As @iwillnot wrote:
Driver You can read more in detail what the Driver is all about from the documentation. In summary, it simply allows you to rely on these properties: - Can't error out - Observe on main scheduler - Sharing side effects
if you use Driver
, you won't have to specify observeOn
, shareReplay
nor catchErrorJustReturn
.
In summary, the code above is similar to this one using Driver
:
let intDriver = sequenceOf(1, 2, 3, 4, 5, 6)
.asDriver(onErrorJustReturn: 1)
.map { $0 + 1 }
.filter { $0 < 5 }