lundi 8 février 2016

Where does regex go in an iOS app using the MVC design pattern?

I am writing an iOS app in swift and in like every app I need to request user input in several of my screens. I would like to follow good design patterns while designing my app and I am mainly focusing on the Model-View-Controller design pattern right now. I will focus on the User Registration and Sign In screens to explain my scenario. I have a User Registration Screen and a Sign In page which both share similar input fields such as: email and password

I have the following classes so far in order to follow MVC pattern:

Model classes: User.swift

View classes: UserView.swift

Controller Classes: UserRegistrationViewController.swift, SignInViewController.swift

The issue I am having now in terms of design is that in each view controller class I validating each input field mostly using regex. As you can probably guess this means that I have ended up with a lot of repeated code in both view controllers. For instance, I am validating the email and password exactly the same way in both view controllers. Thus, how should I solve this and still follow MVC? I am leaning towards having a Validator class with several validator functions that can be called and reused from each view controller and also perhaps a Regex class that will contain regex only? or should this be some type of Properties file?

Aucun commentaire:

Enregistrer un commentaire