應(yīng) HS 項(xiàng)目需求最近開(kāi)始學(xué)習(xí)
RxSwift
,本文主要記述在github
上RxSwift
的項(xiàng)目 Rx.playground 的官方文檔自認(rèn)為需要的進(jìn)行翻譯
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.
譯文
每一個(gè) Observable 實(shí)例都是一個(gè)序列
Observable 序列相比Swift序列的而言,關(guān)鍵優(yōu)點(diǎn)是它還可以異步接收元素。 這是RxSwift的本質(zhì)接校。 一切都在這個(gè)概念上擴(kuò)展熟掂。
- 一個(gè) Observable (ObservableType) 就等同于一個(gè)序列
- ObservableType.subscribe(_:) 方法等同于 Sequence.makeIterator()
[本文作者注:makeIterator就是迭代器的意思苔严,通俗點(diǎn)就是遍歷器] - ObservableType.subscribe(_ :)采用觀察者(ObserverType)參數(shù)际度,該參數(shù)將被訂閱用于自動(dòng)接收由Observable發(fā)出的序列事件和元素工秩,而不是在返回的生成器上手動(dòng)調(diào)用next()云稚。
[本文作者注:此處很重要隧饼,對(duì)于了解subscribe有很大的作用,反正我是在這里暈了好久]