Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created October 24, 2017 16:50
Show Gist options
  • Select an option

  • Save azamsharp/b7af1b3dda36a8592433672041a1145b to your computer and use it in GitHub Desktop.

Select an option

Save azamsharp/b7af1b3dda36a8592433672041a1145b to your computer and use it in GitHub Desktop.
struct ChangePasswordViewModel : ViewModel {
var brokenRules: [BrokenRule] = [BrokenRule]()
var newPassword = Dynamic<String>("")
var confirmPassword = Dynamic<String>("")
var isValid :Bool {
mutating get {
self.brokenRules = [BrokenRule]()
self.validate()
return self.brokenRules.count == 0 ? true : false
}
}
}
extension ChangePasswordViewModel {
mutating private func validate() {
if newPassword.value != confirmPassword.value {
self.brokenRules.append(BrokenRule(propertyName: "confirmPassword", message: "Passwords are not matching"))
}
if (newPassword.value?.count)! < 8 {
self.brokenRules.append(BrokenRule(propertyName: "newPassword", message: "Password should be at least 8 characters long"))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment