0

im stucked with this situation

This is the view raidobuttons and label are inside of a stackview

    var radioButton: RadioButton = RadioButton(duration: 0).usingAutoLayout()
    var radioButtonNo: RadioButton = RadioButton(duration: 0).usingAutoLayout()
    let lblYes: UILabel = UILabel().usingAutoLayout()
    let lblNo: UILabel = UILabel().usingAutoLayout()

The model im working with input and output, but i don“t know if i should set the control on viewmodel or in controller

and whats the sequence?

Model:

   struct Input {
        let trigger: Driver<Void>
        let viewWillAppear: Driver<Void>
        let callingCodeTap: Driver<Void>
        let yesTap: Driver<Void>
        let phoneNumber: Driver<String>
        let callingCodeDidBeginEditing: Driver<Void>
        let phoneNumberDidEndEditing: Driver<Void>
        let actionBtnTap: Driver<Void>
    }

    struct Output {
        let triggered: Driver<Void>
        let viewWillAppear: Driver<Void>
        let callingCodeTapped: Driver<Country>
        let yesTapped: Driver<Void>
        let country: Driver<Country>
        let phoneNumber: Driver<(Bool, Phone)?>
        let callingCodeDidBeginEditing: Driver<Void>
        let phoneNumberDidEndEditing: Driver<Void>
        let actionBtnTapped: Driver<Void>
        let error: Driver<IBANError>
    }

And finally the controler

         output
        .yesTapped
        .do(onNext: { print("test")})
Zac Mazk
  • 1
  • 3

1 Answers1

0

Basing on the code in your controller the most probable reason why the closure in the .do operator is no called is that there is no subscription created for this observable. .do is just an operator just like .map etc.. You need the "end" in your sequence (observers produces values for subscribers) in this case you are missing the subscriber.

You have 2 options to solve your problem:

Add subscription and stay with "do" operator

         output
        .yesTapped
        .do(onNext: { print("test")})
        .subscribe()

Handle the values directly in subscription closures

         output
        .yesTapped
        .subscribe(onNext: { print("test") })

Remember to keep the subscription alive as long as you need it

For example you could use DisposeBag for that.

To do that you need an instance of DisposeBag in the place that will keep the lifecycle of the subscription. In your case controller might be the right place.

Simply create new property in your controller's class scope

private let disposeBag = DisposeBag()

and add .disposed(by: disposeBag) after the .subscribe( ... ) method and your subscription will be alive as long as the controller is alive.

The final result would be

         output
        .yesTapped
        .subscribe(onNext: { print("test") })
        .disposed(by: disposeBag)