Rxswift: Ambiguous reference to member 'text' for UITextField.rx.text

Created on 11 Nov 2016  Â·  15Comments  Â·  Source: ReactiveX/RxSwift

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?

Most helpful comment

The problem is probably cause by the fact we've changed rx.text to be ControlProperty<String?>.

For that purpose we've added orEmpty extension.

Just use:

passwordTextField.rx.text.orEmpty.subscribe(onNext: {
})

All 15 comments

Hi @lizixroy! What was the solution here? (Running into the same thing…)

Hi,

It turned out that this error was caused by us having a "text" property in one of our own classes that conform to Rx's protocols.

It's not a RxSwift problem.

Make sure to check for the same problem in your codebase.

Roy

iPhone$B$+$iAw?.(B

2016/11/15 20:46$B!"(BRyan Coppolo [email protected] $B$N%a%C%;!<%8(B:

Hi @lizixroy! What was the solution here? (Running into the same thing$B!D(B)

$B!=(B
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Hi,

I am having a similar problem but when trying to bind a collectionView

.bindTo(lectureViewList.rx.items)

It says ambiguous reference to member items. The thing is that I used this binding method before on the same project and it works there so I do not know why it does not work here. Any ideas?

The problem is probably cause by the fact we've changed rx.text to be ControlProperty<String?>.

For that purpose we've added orEmpty extension.

Just use:

passwordTextField.rx.text.orEmpty.subscribe(onNext: {
})

@bertadevant did you manage to solve your issue. I am running into the same issue.

Hi,
I am also facing similar problem when trying to bind a UITableView :
.bindTo(tableView.rx.items)

@Yogesh-Bhatt If this is of any help, I got around the issue here, https://github.com/nim23/pokedex-reactivex/blob/master/Pokedox/MainViewController.swift#L33. The closure made the compiler error go away. I basically took it from here https://github.com/ReactiveX/RxSwift/blob/44cee5305013247a1e83d1adb8630de68e0a8ac5/RxCocoa/iOS/UITableView%2BRx.swift#L37.

@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.

screen shot 2017-01-22 at 8 05 13 pm

temporary solution from me: put text into a variable first, then you can call the subscribe

example:

var text = textField.rx.text

text.subscribe(onNext:{ (typedText) in
            //do something here
        }).addDisposableTo(disposeBag)

I get the same thing under Xcode 8.3 (Swift 3.1) with NSButton.rx.tap. The temp variable solution doesn't seem to work for me.

error

import UIKit
import RxSwift
import RxCocoa

class ViewController: UIViewController {

@IBOutlet weak var txtField: UITextField!
@IBOutlet weak var btn: UIButton!

let disposeBag = DisposeBag()
let txtFieldText = Variable("")

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    txtField.rx.text.bindTo(txtFieldText).addDisposableTo(disposeBag)
}

}

Hello, guys. I've got the code but it doesn't work. How can I it fix?

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!

FYI, future people reading this. The reason for getting @bertadevant 's issue is that basically the swift compiler can figure out the inputs / return types of the closure so you have to be explicit and the error message should go away

billionssg fix worked for me. Xcode wouldn't autocomplete textField.rx.text, so I couldn't .bind(to:) it. Now I can:

public func setup(bindTo input: Variable<String?>?){
        if let input = input {
            let a = self.textField.rx.text
            a.bind(to: input)
        }
}

Same error with RxCocoa 4.1.2:
demoTextField.rx.text.orEmpty .bind(to: demoTextLabel.rx.text) .disposed(by: disposeBag)
gives:

` Ambiguous reference to member 'text'

Found this candidate (RxCocoa.Reactive)

Found this candidate (RxCocoa.Reactive)

Found this candidate (RxCocoa.Reactive)

Found this candidate (RxCocoa.Reactive)`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

retsohuang picture retsohuang  Â·  3Comments

kzaher picture kzaher  Â·  3Comments

trungp picture trungp  Â·  3Comments

trant picture trant  Â·  3Comments

jaumard picture jaumard  Â·  3Comments