VillyG
VillyG

Reputation: 155

combineLatest on array in RxSwift

The code below was demonstrated by Ash Furrow during an FRP presentation and using RxSwift. Unfortunately the "combineLatest" operator of RxSwift only allows for up to 10 observables. I am looking for a workaround to get the same result but on an array of observables instead.

Any ideas?

class SignupDemoViewController: UIViewController {
  @IBOutlet weak var emailAddressTextField: UITextField!
  @IBOutlet weak var passwordTextField: UITextField!
  @IBOutlet weak var signupButton: UIButton!

  let disposeBag = DisposeBag()

  override func viewDidLoad() {
    super.viewDidLoad()

    let emailIsValid = emailAddressTextField.rx_text >- map (isEmail)
    let passwordIsValid = passwordTextField.rx_text >- map (isPassword)

    combineLatest(emailIsValid, passwordIsValid)
        >- and
        >- signupButton.rx_subscribeEnabledTo
        >- disposeBag.addDisposable

    signupButton.rx_tap
        >- signup
        >- display
        >- disposeBag.addDisposable
  }
}

Upvotes: 1

Views: 3699

Answers (2)

Julian
Julian

Reputation: 103

It's now Observable.combineLatest(array) instead of array.combineLatest.

Upvotes: 2

kzaher
kzaher

Reputation: 66

Array versions of combineLatest and zip are supported from version of RxSwift-2.0-alpha.1 forward.

Hope this helps.

Upvotes: 5

Related Questions