0

I did with below code for passing single parameter.

lazy var priceListData: Observable<FoodPrice> = {
        return self.foodNamesparams1.asObservable()
                   .flatMapLatest(ApiCallViewModel.foodList(_:))
}

But I don't know how to pass multiple parameters..
If I need to pass foodNamesparams1, foodNamesparams2 to ApiCallViewModel.foodList
How can I do it with RxSwift?

foodNamesparams1 and foodNamesparams2 both are BehaviorRelay

AjinkyaSharma
  • 1,870
  • 1
  • 16
  • 26
  • check this https://stackoverflow.com/questions/34095592/rxswift-use-zip-with-different-type-observables – Daljeet Feb 18 '20 at 06:27
  • This might be helpful: https://medium.com/@danielt1263/recipes-for-combining-observables-in-rxswift-ec4f8157265f – Daniel T. Feb 19 '20 at 00:58

1 Answers1

0

You most likely want to combine the parameters first, most likely via combineLatest or zip.

This will looks something like this

Observable.combineLatest(
    foodNamesparams1.asObservable(),
    foodNamesparams2.asObservable()
  )
  .flatMapLatest(ApiCallViewModel.foodList)

CombineLatest will not emit anything unless both combined observables have emitted at least once - and then it will commit on any update of either combined observable.

Check out the combining section here http://reactivex.io/documentation/operators.html#combining to find the best suited combination method

MarkHim
  • 5,686
  • 5
  • 32
  • 64