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?
@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!
Most helpful comment
Hi there!
I'm interested in knowing how to overload the function to admit more than 8 arguments, thanks!