使用 RxSwift、驱动程序并绑定到
use RxSwift, driver and bind to
第一次提问,正在学习RxSwift,bind to和driver怎么用,driver和bind有什么区别to.Anyone else学习RxSwift now.If你正在学习RxSwift或Swift或OC,希望我们能成为朋友,互相学习。
我建议您阅读 RxSwift Traits 的文档,例如 Driver。
为什么要使用 Traits?
Swift has a powerful type system that can be used to improve the correctness and stability of applications and make using Rx a more intuitive and straightforward experience.
通过使用遵循约束的单元,如果我们试图做一些我们不应该做的事情(例如,在 [= 上执行 UI 代码,我们可以依靠编译器向我们显示错误50=]的drive
方法)。
这与为什么我们根据上下文或问题的适当性使用堆栈和队列等数据结构的概念相同。
Driver
您可以从文档中更详细地阅读 Driver is all about 的内容。总之,它只允许您依赖这些属性:
- 不能出错
- 观察主调度程序
- 分享副作用
这在处理用户界面时很常见。
为什么叫它Driver
Its intended use case was to model sequences that drive your application.
社区
如果你有兴趣认识like-minded和新老RxSwift-ers,就来join the RxSwift community in Slack吧。 :)
- 引用自 RxSwift 的文档。
@iwillnot 回复很好,但我会尝试通过示例进行改进:
假设您有以下代码:
let intObservable = sequenceOf(1, 2, 3, 4, 5, 6)
.observeOn(MainScheduler.sharedInstance)
.catchErrorJustReturn(1)
.map { [=10=] + 1 }
.filter { [=10=] < 5 }
.shareReplay(1)
正如@iwillnot 所写:
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
,则不必指定 observeOn
、shareReplay
或 catchErrorJustReturn
.
总之,上面的代码与使用 Driver
:
的代码类似
let intDriver = sequenceOf(1, 2, 3, 4, 5, 6)
.asDriver(onErrorJustReturn: 1)
.map { [=11=] + 1 }
.filter { [=11=] < 5 }
第一次提问,正在学习RxSwift,bind to和driver怎么用,driver和bind有什么区别to.Anyone else学习RxSwift now.If你正在学习RxSwift或Swift或OC,希望我们能成为朋友,互相学习。
我建议您阅读 RxSwift Traits 的文档,例如 Driver。
为什么要使用 Traits?
Swift has a powerful type system that can be used to improve the correctness and stability of applications and make using Rx a more intuitive and straightforward experience.
通过使用遵循约束的单元,如果我们试图做一些我们不应该做的事情(例如,在 [= 上执行 UI 代码,我们可以依靠编译器向我们显示错误50=]的drive
方法)。
这与为什么我们根据上下文或问题的适当性使用堆栈和队列等数据结构的概念相同。
Driver
您可以从文档中更详细地阅读 Driver is all about 的内容。总之,它只允许您依赖这些属性:
- 不能出错
- 观察主调度程序
- 分享副作用
这在处理用户界面时很常见。
为什么叫它Driver
Its intended use case was to model sequences that drive your application.
社区
如果你有兴趣认识like-minded和新老RxSwift-ers,就来join the RxSwift community in Slack吧。 :)
- 引用自 RxSwift 的文档。
@iwillnot 回复很好,但我会尝试通过示例进行改进:
假设您有以下代码:
let intObservable = sequenceOf(1, 2, 3, 4, 5, 6)
.observeOn(MainScheduler.sharedInstance)
.catchErrorJustReturn(1)
.map { [=10=] + 1 }
.filter { [=10=] < 5 }
.shareReplay(1)
正如@iwillnot 所写:
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
,则不必指定 observeOn
、shareReplay
或 catchErrorJustReturn
.
总之,上面的代码与使用 Driver
:
let intDriver = sequenceOf(1, 2, 3, 4, 5, 6)
.asDriver(onErrorJustReturn: 1)
.map { [=11=] + 1 }
.filter { [=11=] < 5 }