Skip to content

Commit

Permalink
Merge pull request #40 from KVTaniguchi/refactorValidationRule
Browse files Browse the repository at this point in the history
apply rules with map and filter
  • Loading branch information
jpotts18 committed Jul 21, 2015
2 parents dc9224c + b959029 commit ca65096
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Validator/ValidationRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ public class ValidationRule {
}

public func validateField() -> ValidationError? {
for rule in rules {
if !rule.validate(textField.text) {
return ValidationError(textField: self.textField, errorLabel:self.errorLabel, error: rule.errorMessage())
}
}
return nil
return rules.filter{ !$0.validate(self.textField.text) }
.map{ rule -> ValidationError in return ValidationError(textField: self.textField, errorLabel:self.errorLabel, error: rule.errorMessage()) }.first
}
}

0 comments on commit ca65096

Please sign in to comment.