title: Assigning value chosen from a UIPicker to a UITextField in Swift (also how to show and hide it)
body: <p>The title says it all. I am trying to assign a value (gender) that the user will select from a UIPicker and then the value will appear as the UITextField input using Swift.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>class RegistrationViewController: UIViewController, UIPickerViewDelegate, UITextFieldDelegate {
  
  @IBOutlet var getGender: UIPickerView! = UIPickerView()
  
  @IBOutlet var genderTextField: UITextField! = nil
  
  let gender = ["Male", "Female", "Other"]
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      self.genderTextField.inputView = pickerView
  
      // Do any additional setup after loading the view.
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  // returns the number of 'columns' to display.
  func numberOfComponentsInPickerView(pickerView: UIPickerView!) -&gt; Int{
      return 1
  }
  
  // returns the # of rows in each component..
  func pickerView(pickerView: UIPickerView!, numberOfRowsInComponent component: Int) -&gt; Int{
      return gender.count
  }
  
  func pickerView(pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int) -&gt; String! {
      return gender[row]
  }
  
  func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int)
  {
      genderTextField.text = "\(gender[row])"
  
  }
  </code></pre>
  
  <p>I am aware that this could be achieved if instead of a textfield I use a label and format it to look as a textfield. Then changing the value of the label.</p>
  
  <p>I would also like to know how to show/hide the UIPicker when the label/textfield is clicked. Could anyone help me out with that?</p>
  
  <p>Thank you so much for your advice!</p>
  
  <p>Cheers.</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>I have done everything but the only thing that the compiler complains about is the line with the comment //ERROR. As I mentioned, it does not accept only this:</p>
  
  <pre><code>self.genderTextField.inputView = pickerView   //ERROR -&gt; Requires more declarations! Read update section below!
  </code></pre>
  
  <p>It asks me to provide extra declarations such as:</p>
  
  <pre><code>pickerView!(pickerView: UIPickerView?, didSelectRow: Int, inComponent: Int) 
  
  pickerView!(pickerView: UIPickerView?, numberOfRowsInComponent: Int)
  </code></pre>
  
  <p>There are a couple other suggestions from Xcode but I do not know which one to use and how.</p>
  
  <p>Help please!</p>
  
  <p>Thanks!</p>