使用 RxSwift、驱动程序并绑定到 [英] use RxSwift, driver and bind to

查看:45
本文介绍了使用 RxSwift、驱动程序并绑定到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次提问,我正在学习RxSwift,如何使用bind to和driver,driver和bind to有什么区别.现在还有人在学习RxSwift.如果你正在学习RxSwift或者Swift 或 OC,希望我们能成为朋友,互相学习.

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 回应很好​​,但我会尝试用一个例子来改进它:

@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)

正如@iwillnot 写道:

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

如果您使用Driver,则不必指定observeOnshareReplaycatchErrorJustReturn.

if you use Driver, you won't have to specify observeOn, shareReplay nor catchErrorJustReturn.

总而言之,上面的代码与使用Driver的代码类似:

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 }

更多详情

这篇关于使用 RxSwift、驱动程序并绑定到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆