title: Set focus on a next textfield when user has typed 2 characters in Swift
body: <p>I'm desperately looking for someone who could answer my question.
  I have a form with 4 TextFields. I want that when the user has typed 2 chars, the focus is automatically set on the next TextField.</p>
  
  <p>I've tried the following code :</p>
  
  <pre><code>func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -&gt; Bool {
      guard let text = textField.text else { return true }
      //let newLength = text.characters.count + string.characters.count - range.length
  
  
      if (text.characters.count == 2 &amp;&amp; textField.tag == 10){
          textField.resignFirstResponder()
          self.txt_min_debut.becomeFirstResponder()
          return false
      }
  
      else if (text.characters.count == 2 &amp;&amp; textField.tag == 11){
          textField.resignFirstResponder()
          self.txt_heure_fin.becomeFirstResponder()
          return false
      }
  
      else if (text.characters.count == 2 &amp;&amp; textField.tag == 12){
          textField.resignFirstResponder()
          self.txt_min_fin.becomeFirstResponder()
          return false
      }
  
      else if (text.characters.count == 2 &amp;&amp; textField.tag == 13){
          textField.resignFirstResponder()
          self.txt_cr.becomeFirstResponder()
          return false
      }
  </code></pre>
  
  <p>It doesn't work like I want. When I type 2 chars, the focus is still on the same TextField. I have to type on a 3rd char to move on the next one.
  Another problem is that the del key is recognized as a key. That means, when I type 2 chars, I can't edit it again.</p>
  
  <p>I'm working with Xcode and Swift 2.</p>