【发布时间】:2017-06-19 07:25:02
【问题描述】:
您好,我是 Swift 开发新手。我正在开发用于用户输入字段验证的代码。我已经导入了 Validator 和 SwiftValidator 库。我无法摆脱这个错误。我也遵循了更新的语法,但错误仍然存在。
代码如下:
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)
}
}
}
提前致谢。
【问题讨论】:
-
您是否尝试验证电子邮件地址是否有效?
-
是的。使用验证器..这是一年前开发的遗留代码。现在我正在更新更改。 @Alwin
标签: ios swift validation compiler-errors xcode8