间取值
2017 - 07 - 26
代码
let A = PublishSubject<Void>()
let B = PublishSubject<String>()
let observable = A.withLatestFrom(B)
// let observable = B.sample(A)
let disposable = observable.subscribe(onNext: { value in
print(value)
})
B.onNext("Par")
B.onNext("Pari")
B.onNext("Paris")
A.onNext()
A.onNext()
下面各方法替换后的输出
withLatestFrom
Paris
Paris
A取时序和值 B只取最新值(B时序无用)
与CombineLatest区别:
两信号时序和值均取 每个信号流触发时 结合两信号流最新值
sample
Paris
A取时序 B取值
且若B值未更新 不输出
注: A作为参数传入