Hugo Alonso Hugo Alonso - 4 months ago 11
iOS Question

RxSwift - fetch every item on the list

I have a method that receives

[Int]
, which are ids of some Items.

I'd like to go through this list and download every Item using another method that returns/download
Observable<Item>
to finally return an
Observable<[Item]>
in this very same function.

How can I do this using RxSwift/RxCocoa operators?

Answer

This is an easy one! There's a couple of sneaky protocol extensions for arrays of observables built into the library.

list.map { Int->Observable<Item> in
    downloadItem($0)
}
.zip { $0 }