RxSwift: Ambiguous reference to member 'text' for UITextField.rx.text
After upgraded to XCode 8.1(8B62), I get this error “Ambiguous reference to member ‘text’” everywhere I use rx.text.
For example:
passwordTextField.rx.text.subscribe(onNext: {
// do something here ...
}).addDisposableTo(disposeBag)
This is an error and the project cannot be compiled. Any idea on how to fix this?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (1 by maintainers)
The problem is probably cause by the fact we’ve changed
rx.text
to beControlProperty<String?>
.For that purpose we’ve added
orEmpty
extension.Just use:
@nim23 Thanks for quick reply and here I am also using closure but its showing me same compile error. I am not sure what wrong is happening here.
@bertadevant did you manage to solve your issue. I am running into the same issue.
Hi @petrovRV you are binding a variable to a text field? as in the textfield is the driving force? it should change the variable?
Because if yes, it should change the variable then you have to bind it to the
txtFieldText.value
not the variable itself.If your textField is not mean to change the variable but the variable has to change the textField you need to
txtFieldText.asObservable().bind(to: txtField.rx.text)
Most of the times you have this ambiguous reference issue is because the result you are trying to bind is not in the right format. If value still gives you issues try adding a
.map { $0 }
before bidding and make sure you are getting a string not aReactive<String>
Hope it helps!
temporary solution from me: put text into a variable first, then you can call the subscribe
example: