代码之家  ›  专栏  ›  技术社区  ›  Winston Du

RxSwift:让一个中继从一个数组连续地接受项

  •  0
  • Winston Du  · 技术社区  · 4 年前

    let array = [1, 2, 3, 4, 5]
    

    假设我还有一个接受Int元素的发布中继

    let relay = PublishRelay<Int>()
    

    有没有比在我的数组上循环把它们塞进中继更好的方法吗?

    for num in array {
       relay.accept(num)
    }
    
    0 回复  |  直到 4 年前
        1
  •  2
  •   Daniel T.    4 年前

    这个 Observable.from

    Observable.from(array)
        .bind(to: relay)