Input from UITextField connected from storyboard to Swift view controller file

后端 未结 1 1540
Happy的楠姐
Happy的楠姐 2021-01-02 04:37

Using Swift, how do I get the input from a UITextField?

In my Main.storyboard, I have chosen a \"Text Field\" from the premade components and dragged it

相关标签:
1条回答
  • 2021-01-02 04:59

    Yes, your approach of creating an IBOutlet from the storyboard and referencing it using self.myInput.text is a standard way of accessing this field in Swift.

    As for whether to use self.myInput vs. myInput, I prefer to always write self because it is very obvious that the variable is a property and will probably be changed in many different places (opposed to a local var). Also, once you have self there, you don't have to worry about introducing local vars with the same name or making changes if you copy and paste a block of code into a closure that requires self.

    0 讨论(0)
提交回复
热议问题