Validating conditions for enabling sign-up button On an authentication view, there are some inputs, like password, email, etc and a sign up button which is enabled only if theses inputs are not empty.

So what I have is this function: 

func canSignUpButtonBeEnabled() -&gt; Bool {

    let password = self.passwordTextField.text.stringByReplacingOccurrencesOfString(" ", withString: "")

    return (!self.emailTextField.text.isEmpty &amp;&amp; !self.passwordTextField.text.isEmpty
            &amp;&amp; !self.firstNameTextField.text.isEmpty  &amp;&amp; !self.lastNameTextField.text.isEmpty
            &amp;&amp; countElements(password) &gt;= 4)

}


And after each character entered by the user, I set on the enable property of my button the result of this function.

So I was wondering if there is a cleaner solution to do it?
You bind password but then in your return logic you use self.passwordTextField.text.isEmpty which seems to be wrong - but would get caught by countElements(password) &gt;= 4 later.

This would be arguably more readable, and perhaps modular, if you introduced intermediate predicates.  Like such:

class Whatever {

  func hasName () -&gt; Bool {
    return !self.firstNameTextField.text.isEmpty  &amp;&amp;              
           !self.lastNameTextField.text.isEmpty
  }

  func hasEmail () -&gt; Bool { 
    return !self.emailTextField.text.isEmpty
  }

  func hasValidPassword () -&gt; Bool {
    let password = self.passwordTextField.text.stringByReplacingOccurrencesOfString(" ", withString: "")
    return countElements(password) &gt;= 4
  }

  func canSignUpButtonBeEnabled() -&gt; Bool {
    return hasEmail() &amp;&amp; hasName() &amp;&amp; hasValidPassword()
  }
}