From b95902919b8e4648a16fbaaf799893f452d6e8f4 Mon Sep 17 00:00:00 2001 From: Kevin Taniguchi Date: Sun, 28 Jun 2015 15:55:19 -0400 Subject: [PATCH] apply rules with map and filter --- Validator/ValidationRule.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Validator/ValidationRule.swift b/Validator/ValidationRule.swift index eb0e333..88b95ce 100644 --- a/Validator/ValidationRule.swift +++ b/Validator/ValidationRule.swift @@ -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 } } \ No newline at end of file