0
你好,我是Swift開發新手。我正在開發一個用於用戶輸入字段驗證的代碼。我輸入了Validator和SwiftValidator
庫。我無法擺脫這個錯誤。我也跟着更新的語法,但仍然錯誤仍然存在。'ValidationError'不能轉換爲'Error';你的意思是使用'as!'強迫低調?
下面是代碼:
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
是的。使用Validator ..它是一年前開發的遺留代碼。現在我正在更新這些更改。 @Alwin – SrkRaj