title: Swift - validating UITextField
body: <p>I have these outlets in my app:</p>
  
  <pre><code>@IBOutlet var name1: UITextField!
  
  @IBOutlet var name2: UITextField!
  
  @IBOutlet var name3: UITextField!
  
  @IBOutlet var name4: UITextField!
  
  @IBOutlet var newButton: UIButton!
  </code></pre>
  
  <p>What I tried to do is the following: </p>
  
  <p>Every time the user types something in one of these four <code>UITextField</code>s or deletes something, I want to check if any <code>UITextField</code> is empty</p>
  
  <p>If any <code>UITextField</code> is empty, the button should be disabled.</p>
  
  <p>If all <code>UITextField</code>s are set (not empty), the button should be enabled.</p>
  
  <p>My code:</p>
  
  <pre><code>func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -&gt; Bool {
  
      setButton()
  
      return true
  }
  
  func setButton() {
  
      let inputValid = checkInput()
  
      if inputValid {
  
          newButton.enabled = true
  
      } else {
  
          newButton.enabled = false
  
      }
  
  }
  
  func checkInput() -&gt; Bool {
  
      let name1Value = name1.text
      let name2Value = name2.text
      let name3Value = name3.text
      let name4Value = name4.text
  
      if !name1Value.isEmpty &amp;&amp; !name2Value.isEmpty &amp;&amp; !name3Value.isEmpty &amp;&amp; !name4Value.isEmpty {
  
          return true
  
      }
  
      return false
  
  }
  </code></pre>
  
  <p>Ok, it works 50% for now.</p>
  
  <p>When I type one character in each <code>UITextField</code>, the button is still disabled.</p>
  
  <p>When I add a second one to any <code>UITextField</code>, the button gets enabled etc...</p>
  
  <p>Can anyone help me with this?</p>