Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Validating Form Field in IOS

I have imported as below:

import SwiftValidator

Below is my ViewController class:

class OriginShipmentViewController: BaseViewController, OriginShipmentView {
     let validator = Validator()
}

You can see that I have initialised validator

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Below is the button save click code:

buttonSave?.configureAppearance(
        appearance.mainButtonAppearance, title: localizedKey(key: "origin.next"))
    buttonSave?.addTargetClosure(closure: {_ in
        self.onclickSave()
    })

So you can notice ther is a method call named self.onclickSave() which is as below:

func onclickSave() {
    validator.validate(self)
}

Here, on this line : validator.validate(self) I am getting compile time error as below:

No exact matches in call to instance method ‘validate’

What might be the issue? Thanks in advance.

>Solution :

You have not conformed ValidationDelegate yet. By default, this protocol requires two functions validationSuccessful and validationFailed. Try to put these lines of code:

extension OriginShipmentViewController: ValidationDelegate {
    func validationSuccessful() {
        //TODO: 
    }
    
    func validationFailed(_ errors: [(Validatable, ValidationError)]) {
        //TODO: 
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading