Unfortunately we all know that we can’t put everything what we are working in, on a simple blog, I have to understand this since years ago when I worked at some government department. But I can show what I am doing now just for fun and for registry to me in the future.
we were had some problems here, especially when we’d need to try validate a lot of forms that involved things like UITextField, UISegmentedControl, etc. To solve this issue I had to create one class with methods like:
.insert(object, checkType, labelError, errorMessage) // magic goes here.
.showErrors() // print on screen all erros like below
.count() // return the quantity of erros below
.result() // return if all tests are passed or no.
and the code is easily readable:
You set a trigger for validation, here a button to Next Screen. Then you assign function pointers to the stack os Validations.
Then you make a function validation to the object assigned. This coule be simple as
or a little more complex like this (a validation check for social number in Brazil), validating screen in iOS with and the results are below: