0

I have a requirement to get responses from multiple requests with different models in RxSwift. I want to do this without GCD or Semaphore and only with RxSwift. I try this code but have some problems with in different responses with different models and counts of results objects.

 Observable.zip(service.fetchAlbums(), service.fetchUsers())
.subscribe(onNext: { (albums, users) in
        print(albums)
        print(users)
    })
    .disposed(by: self.disposeBag)

1 Answers1

0

The following works fine.

import RxSwift

func example(service: Service, disposeBag: DisposeBag) {
    Observable.zip(service.fetchAlbums(), service.fetchUsers())
        .subscribe(onNext: { (albums, users) in
            print(albums)
            print(users)
        })
        .disposed(by: disposeBag)
}

protocol Service {
    func fetchAlbums() -> Observable<[Album]>
    func fetchUsers() -> Observable<[User]>
}

struct Album { }
struct User { }
Daniel T.
  • 32,821
  • 6
  • 50
  • 72