Created
October 24, 2017 16:50
-
-
Save azamsharp/b7af1b3dda36a8592433672041a1145b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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