Rxswift: How does the array version of combineLatest work

Created on 12 Nov 2015  路  3Comments  路  Source: ReactiveX/RxSwift

Hi I'm trying to understand how the array version of combineLatest works and I'm getting nowhere. I've searched the docs and sources, but didn't find anything yet.

To illustrate my problem, let's say I have two Variable-instances

let v1 = Variable<String>("")
let v2 = Variable<Int>(0)

For starters I use one inside an array and everythings' fine:

[v1].combineLatest { v -> Observable<Bool> in ... } ... // all ok here

Now to the real usecase:

[v1, v2].combineLatest ... // compiler says no

So the compiler is complaining, that NSArray has no method combineLatestwhich is correct. So I guess I have to provide more hints about the type, but how? I can't use the ObservableConvertibleType as a type for an array, so I'm pretty much stuck. I know there are overloads of combineLatest up to 8 arguments which satisfy my needs, but I'd like to know how the array version works anyway.

Could somebody please provide an example?

Most helpful comment

Hi there!
I'm interested in knowing how to overload the function to admit more than 8 arguments, thanks!

All 3 comments

@tyregor ,

For array version of combineLatest to work, Variables need to be of the same type :)

let v1 = Variable<String>("a")
let v2 = Variable<String>("b")

[v1, v2].combineLatest { (arrayOfStrings: [String]) in .... }

If you want to use different types, then you do

let v1 = Variable<String>("a")
let v2 = Variable<Int>(1)
combineLatest(v1, v2)  { (a: String, b: Int) in .... }

@kzaher ,

thank you very much.

Hi there!
I'm interested in knowing how to overload the function to admit more than 8 arguments, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RafaelPlantard picture RafaelPlantard  路  3Comments

retsohuang picture retsohuang  路  3Comments

jaumard picture jaumard  路  3Comments

dmial picture dmial  路  3Comments

gaudecker picture gaudecker  路  3Comments