[英]'ValidationError' is not convertible to 'Error';did you mean to use 'as!' to force downcast?
Hello I'm new to Swift development. 您好,我是Swift开发的新手。 I'm developing a code for user input field validation. 我正在开发用于用户输入字段验证的代码。 I've imported Validator and SwiftValidator
libraries. 我已经导入了Validator和SwiftValidator
库。 I couldn't get rid of this error. 我无法摆脱这个错误。 I followed the updated syntax too but still the error persists. 我也遵循更新的语法,但错误仍然存在。
Here is the code: 这是代码:
func addFieldValidation() {
var emailRules = ValidationRuleSet<String>()
emailRules.add(rule: ValidationRulePattern(pattern: .EmailAddress, error: ValidationError(textField:emailTextField, error: "Enter valid email address"))) //****<---Getting error here******
emailTextField.validationRules=emailRules;
emailTextField.validateOnInputChange(enabled: true);
emailTextField.validationHandler = { result in
switch result {
case .valid:
self.enableSignUp(true)
case .invalid(let failureErrors):
let messages = failureErrors.map { $0.message }//****<---Getting error here as "Value of type 'Error' has no member 'message' "******
print(messages)
self.enableSignUp(false)
}
}
}
Thanks in advance. 提前致谢。
I have a different way of email validation 我有另一种电子邮件验证方式
// email validation method
func isValidEmail(emailAddress:String) -> Bool {
// print("validate calendar: \(testStr)")
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
return emailTest.evaluate(with: emailAddress)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.