简体   繁体   English

“ ValidationError”不能转换为“ Error”;您是要使用“ as!”吗? 强迫垂头丧气?

[英]'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. 我已经导入了ValidatorSwiftValidator库。 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.

相关问题 斯威夫特 - &#39;AnyObject!&#39; 不能转换为&#39;ViewController&#39;; 你的意思是用&#39;as!&#39; 迫使低垂? - Swift - 'AnyObject!' is not convertible to 'ViewController'; did you mean to use 'as!' to force downcast? &#39;NSString的!&#39; 不能转换为&#39;String&#39;; 您是要使用“ as!”吗? 强迫垂头丧气? - 'NSString!' is not convertible to 'String'; did you mean to use 'as!' to force downcast? 这个错误的原因是什么:“NSIndexPath”不能隐式转换为“IndexPath”; 您的意思是使用 &#39;as&#39; 来显式转换吗?” - What is the reason for this error: “NSIndexPath' is not implicitly convertible to 'IndexPath'; did you mean to use 'as' to explicitly convert?” “ NSData”不能隐式转换为“ Data”; 您是要使用“ as”进行显式转换吗? - 'NSData' is not implicitly convertible to 'Data'; did you mean to use 'as' to explicitly convert? 从“UIViewController?”向下转型? &#39;UIViewController&#39; 只解开可选项; 你的意思是使用“!”? - Downcast from 'UIViewController?' to 'UIViewController' only unwraps optionals; did you mean to use '!'? 是否从“ CLLocation”下调? 到“ CLLocation”仅解开可选部分; 您是要使用&#39;!&#39;吗? - Downcast from 'CLLocation?' to 'CLLocation' only unwraps optionals; did you mean to use '!'? Facebook登录-错误消息:可选类型“ Any?”的值 不展开 你是说用&#39;!&#39; 要么 &#39;?&#39;? - Facebook login - error message: Value of optional type 'Any?' not unwrapped; did you mean to use '!' or '?'? 得到错误“未知的接收者coachMarksView; 您是说WSCoachMarksView错误吗?” - Getting the error “Unknown receiver coachMarksView; Did you mean WSCoachMarksView error?” 使用未解决的标识符“ NavigationLink”; 您是说“ NavigationView”吗? -SwiftUI - Use of unresolved identifier 'NavigationLink'; did you mean 'NavigationView'? - SwiftUI 使用未解决的标识符“连接”; 您是在Auth0中表示“连接”吗? - Use of unresolved identifier 'connections'; did you mean 'Connections' in Auth0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM