@IBAction func testField(_ sender: UITextField) { let testText = sender.text } 

You must pass sender.text to other functions, but the testField function testField not return values. How to be?

Reported as a duplicate by participants aleksandr barakin , HamSter , iluxa1810 , Denis , Suvitruf 8 Nov '16 at 14:32 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • what do you mean? What does the function itself not return? So she should not. Or can not take testText? Then make it variable in the class field. - VAndrJ
  • @VAndrJ he asks it. how to make it variable - Max Mikheyenko
  • and why was a new account to create? - Max Mikheyenko
  • Well, I can't pass testText to the function! I can't get it out of testField! - Igor Zexyy
  • I am told to wait with questions ((( - Igor Zexyy

1 answer 1

Create a variable not in view of the function. Next in the body of the function assign a value to it. And then you can use the variable in any other function.

 var testText: String? @IBAction func testField(_ sender: UITextField) { testText = sender.text } func printTestText() { print(testText!) }