Last active
November 7, 2018 01:32
-
-
Save danielaRiesgo/5aeeb4cbd42d2e116904c1ebdc854a9c 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
enum PasswordError: Error { | |
case tooShort | |
case tooLong | |
case noCapitalLetter | |
} | |
let password = MutableProperty("") | |
let validated: ValidatingProperty<String, PasswordError> = ValidatingProperty(password, { | |
if $0.count < 5 { | |
return .invalid(.tooShort) | |
} | |
if $0.count > 10 { | |
return .invalid(.tooLong) | |
} | |
if $0.filter({ character in String(character).uppercased() == String(character) }).first != .none { | |
return .valid | |
} | |
return .coerced($0.capitalized, .noCapitalLetter) | |
}) | |
validated.producer.startWithValues { | |
print("Producer Value -", $0) | |
print("Value - ", validated.value) | |
} | |
validated.result.producer.startWithValues { | |
print("Result -", $0) | |
} | |
password.value = "hi" | |
password.value = "HELLO" | |
password.value = "too loooooong" | |
password.value = "hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment