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.
RxSwift: Driver Go from: a single observable that updates the entire UI to bindTo and reuse the same observable across the viewController.
Łukasz Mróz iOS Developer Today we will talk about bindings. Don't worry, binding just means connecting and we will connect our Observables with Subjects. There is some terminology that we haven't learned before, so…
RxSwift helps when you need to combine complex asynchronous chains. RxSwift also has types such as Subject, a kind of bridge between the imperative and declarative worlds. The subject can act as an Observable, and at the same time, it can be an Observer, i.e. accept objects and issue events.
@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 }
More details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With