RxSwift: Use Zip with different type observables

This works for me. I tested it in Xcode7, RxSwift-2.0.0-beta

zip(just(1), just("!")) { (a, b) in 
    return (a,b)
}

If you using Singles (RxSwift 5.0+)

Single.zip(single1, single2) {
    return ($0, $1)
}

or

Observable.zip(single1.asObservable(), single2.asObservable()) {
    return ($0, $1)
}

Example:

let task = Single
                .zip(repository.getArrayA(), repository.getArrayB())
                { (a: [A], b: [B]) in
                    return (a, b)
                }                    
                .do(onSuccess: { (zip) in
                let (a, b) = zip

                // your code

                //example: self.updateSomething(a, b)

            })
            .asCompletable()

Here is how to make it work for RxSwift 2.3+

Observable.zip(Observable.just(1), Observable.just("!")) {
    return ($0, $1)
}

or

Observable.zip(Observable.just(1), Observable.just("!")) {
    return (anyName0: $0, anyName1: $1)
}

Tags:

Swift

Rx Swift