title: Index out of range error while using picker view
body: <p>I populated a picker view with different arrays, depending on which textfield you click on. However, whenever I choose the fifth row of the "Untergrund" Array the app crashes with the index out of range error. It shows me that row int = 4 and component int = 0. The error occurs in the line where the first if statement is set in the did select row function. I have no idea why this is happening ...</p>
  
  <p>Here is the relevant code:</p>
  
  <pre><code>@IBOutlet weak var Stadt: UITextField!
  @IBOutlet weak var Strasse: UITextField!
  @IBOutlet weak var Platzart: UITextField!
  @IBOutlet weak var Groesse: UITextField!
  @IBOutlet weak var AnzToreKoerbe: UITextField!
  @IBOutlet weak var Untergrund: UITextField!
  
  // Variable für die Firebase Database
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      Stadt.delegate = self
      Untergrund.delegate = self
      Groesse.delegate = self
      AnzToreKoerbe.delegate = self
      Platzart.delegate = self
      Picker.delegate = self
  }
  
  @IBOutlet weak var Picker: UIPickerView!
  
  var currentData = [""]
  
  let UntergrundArray = ["Asphalt", "Kunstrasen Sand", "Kunstrasen Granulat", "Rasen", "Tartan", " "]
  let StadtArray = ["Norderstedt", "Hamburg", "Berlin", "München"]
  let GroesseArray = [ "2 vs 2", "3 vs 3", "4 vs 4", "5 vs 5"]
  let AnzTorKoerbe = ["1", "2", "3", "4"]
  let Art = ["Fußball", "Basketball"]
  
  func textFieldShouldBeginEditing(_ textField: UITextField) -&gt; Bool{
      if textField.tag == 1{
          currentData = StadtArray
      }else if textField.tag == 2{
          currentData = UntergrundArray
      }else if textField.tag == 3 {
          currentData = GroesseArray
      }else if textField.tag == 4 {
          currentData = AnzTorKoerbe
      }else if textField.tag == 5 {
          currentData = Art
  
      }
  
      Picker.reloadAllComponents()
  
      return false;
  }
  
  func numberOfComponents(in pickerView: UIPickerView) -&gt; Int {
      return 1
  }
  
  func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {
      return currentData.count
  }
  
  func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String? {
      return currentData[row]
  }
  
  func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
      let itemSelected = currentData[row]
  
      print(itemSelected)
  
      if (itemSelected == StadtArray[row]) {
          Stadt.text = StadtArray[row]
      }else if (itemSelected == UntergrundArray[row]) {
          Untergrund.text = UntergrundArray[row]
      }else if (itemSelected == GroesseArray[row]) {
          Groesse.text = GroesseArray[row]
      }else if (itemSelected == AnzTorKoerbe[row]) {
          AnzToreKoerbe.text = AnzTorKoerbe[row]
      }else {
          Platzart.text = Art[row]
      }
  }
  </code></pre>