Combination Operators

  • 將多個 Observable 組合成單個 Observable 運算符。

startWith

  • 開始從某個 Observable 發出元素之前發出指定的元素序列。

每個連續的 startWith 元素都將在前一個 startWith 元素之前添加。

let disposeBag = DisposeBag()

Observable.of("A", "B", "C", "D")
    .startWith("1")
    .startWith("a", "b", "c")
    .subscribe(onNext: {
        print($0)
    })
    .disposed(by: disposeBag)

印出結果

a
b
c
1
A
B
C
D

merge

zip

combineLatest

switchLatest

withLatestFrom