hodov
hodov

Reputation: 69

swift: UITextField does not have a member named text

I have @IBAction on event Editing Did Begin

@IBAction func saveCurrentTextField(sender: UITextField) {

    let myTextField : UITextField = sender as UITextField
    myClass.saveMyTextField(myTextField)

}

And then I have button with @IBAction on event Touch Up Inside

@IBAction func saveValueOfThoseTextField(sender: UIButton) {

    println("Those textField = \(myClass.thoseTextField)")
    let text : String = myClass.thoseTextField.text

}

println return:

UITextField: 0xb289b80; frame = (165 15; 40 30); text = '15'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = NSArray: 0xb28f730>; layer = CALayer: 0xb289cc0

But on string let text : String = myClass.thoseTextField.text I get error: UITextField does not have a member named text

Upvotes: 2

Views: 8037

Answers (2)

sudurrani
sudurrani

Reputation: 56

@IBOutlet var txt_RegNumber: [UITextField]!

you might have like this just remove [] because takes array as default

Upvotes: 2

Grimxn
Grimxn

Reputation: 22517

Try:

let text : String = myClass.thoseTextField!.text

The textfield you are referencing is likely an IBOutlet, and will be optional.

Upvotes: 5

Related Questions