Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'inout UIButton' does not conform to protocol 'ReactiveCompatible'

passWordInputView.inputTextField.rx.controlEvent(.editingDidEnd)
        .bindTo(loginButton.rx.tap)
        .disposed(by: disposeBag)

when password edit done then login

but get error: Type 'inout UIButton' does not conform to protocol 'ReactiveCompatible'

like image 801
AloneMonkey Avatar asked Mar 18 '17 05:03

AloneMonkey


1 Answers

Since RxSwift contains the following line, you can be pretty sure that something else is giving the compiler trouble when you get this error for any NSObject subclass (anything in UIKit).

extension NSObject: ReactiveCompatible { }

In my experience this error happens when trying to use rx methods or operators incorrectly or if there is some syntactical error.

For example I got this error for a collectionView when trying to merge two streams like this

Observable.merge(collectionView.rx.streamOne, streamTwo)

But the correct way to merge the two streams is

Observable.of(collectionView.rx.streamOne, streamTwo).merge()

(Note looks like static Observable.merge was added in RxSwift 3.4)


In your case

You are trying to bind the stream from inputTextField.rx.controlEvent(.editingDidEnd) which is Observable<Void> to loginButton.rx.tap which is an Observable, and not an Observer. In english, button.rx.tap is meant to be observed, and not meant to observe.

You may instead do something like this

inputTextField.rx.controlEvent(.editingDidEnd)
    .subscribe(onNext: { [unowned self] in
        self.inputTextField.userInteractionEnabled = false
        self.doLogin()
    }

You could also merge the streams from the button and the textField as described above :)

like image 163
RyanM Avatar answered Nov 08 '22 04:11

RyanM