应 HS 项目需求最近开始学习
RxSwift
,本文主要记述在github
上RxSwift
的项目 Rx.playground 的官方文档自认为需要的进行翻译
Introduction
1.Why use RxSwift?[未翻译]
2.Concepts
Every Observable instance is just a sequence.
The key advantage for an Observable sequence vs. Swift's Sequence is that it can also receive elements asynchronously. This is the essence of RxSwift. Everything else expands upon this concept.
- An Observable (ObservableType) is equivalent to a Sequence.
- The ObservableType.subscribe(_:) method is equivalent to Sequence.makeIterator().
- ObservableType.subscribe(_:) takes an observer (ObserverType) parameter, which will be subscribed to automatically receive sequence events and elements emitted by the Observable, instead of manually calling next() on the returned generator.
译文
每一个 Observable 实例都是一个序列
Observable 序列相比Swift序列的而言,关键优点是它还可以异步接收元素。 这是RxSwift的本质。 一切都在这个概念上扩展。
- 一个 Observable (ObservableType) 就等同于一个序列
- ObservableType.subscribe(_:) 方法等同于 Sequence.makeIterator()
[本文作者注:makeIterator就是迭代器的意思,通俗点就是遍历器] - ObservableType.subscribe(_ :)采用观察者(ObserverType)参数,该参数将被订阅用于自动接收由Observable发出的序列事件和元素,而不是在返回的生成器上手动调用next()。
[本文作者注:此处很重要,对于了解subscribe有很大的作用,反正我是在这里晕了好久]