Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use RxSwift, driver and bind to [closed]

Tags:

rx-swift

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.

like image 854
GeniusFlow Avatar asked Mar 29 '17 14:03

GeniusFlow


People also ask

What is a driver RxSwift?

RxSwift: Driver Go from: a single observable that updates the entire UI to bindTo and reuse the same observable across the viewController.

What is binding in RxSwift?

Ł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…

When should I use RxSwift?

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.


1 Answers

@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

like image 166
xandrefreire Avatar answered Oct 03 '22 16:10

xandrefreire