Created
August 5, 2018 23:00
-
-
Save Arrlindii/9d7e146ae2dd2c288ee926273c45740a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ValidatorConvertible { | |
func validated(_ value: String?) throws -> String | |
} | |
enum ValidatorType { | |
case email | |
case password | |
case username | |
case projectIdentifier | |
case requiredField(field: String) | |
case age | |
} | |
enum VaildatorFactory { | |
static func validatorFor(type: ValidatorType) -> ValidatorConvertible { | |
switch type { | |
case .email: return EmailValidator() | |
case .password: return PasswordValidator() | |
case .username: return UserNameValidator() | |
case .projectIdentifier: return ProjectIdentifierValidator() | |
case .requiredField(let fieldName): return RequiredFieldValidator(fieldName) | |
case .age: return AgeValidator() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment