More than 8 parameters in combineLatest using RxSwift
Asked Answered
F

1

14

Is there any way to put more than 8 observable in combineLatest in RxSwift?

Here is my current implementation:

let registerUserParameters = Observable.combineLatest(
        firstname.asObservable(),
        lastname.asObservable(),
        email.asObservable(),
        mobile.asObservable(),
        addresses.asObservable(),
        cities.asObservable(),
        pword.asObservable(),
        confirm_pword.asObservable(),
        instagramid.asObservable(),
        facebookid.asObservable()) {
            ($0, $1, $2, $3, $4, $5, $6, $7, $8, $9)
    }

I found out that combineLatest only accept up to 8 parameters based on its function.

public static func combineLatest<O1, O2, O3, O4, O5, O6, O7, O8>(_ source1: O1, _ source2: O2, _ source3: O3, _ source4: O4, _ source5: O5, _ source6: O6, _ source7: O7, _ source8: O8, resultSelector: @escaping (O1.E, O2.E, O3.E, O4.E, O5.E, O6.E, O7.E, O8.E) throws -> Self.E) -> RxSwift.Observable<Self.E> where O1 : ObservableType, O2 : ObservableType, O3 : ObservableType, O4 : ObservableType, O5 : ObservableType, O6 : ObservableType, O7 : ObservableType, O8 : ObservableType)
Flexor answered 17/7, 2019 at 8:26 Comment(0)
D
19

You can just combine the first 8, get the combined observable, then combine the last 2, get the combined observable, then combine the two observables.

let first8 = Observable.combineLatest(
        firstname.asObservable(),
        lastname.asObservable(),
        email.asObservable(),
        mobile.asObservable(),
        addresses.asObservable(),
        cities.asObservable(),
        pword.asObservable(),
        confirm_pword.asObservable()) {
            ($0, $1, $2, $3, $4, $5, $6, $7)
    }

let last2 = Observable.combineLatest(
    instagramid.asObservable(),
    facebookid.asObservable()) {
        ($0, $1)
    }

let registerUserParameters = Observable.combineLatest(first8, last2) {
    ($0.0, $0.1, $0.2, $0.3, $0.4, $0.5, $0.6, $0.7, $1.0, $1.1)
}
Difficult answered 17/7, 2019 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.