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


i writing ios app in swift , in every app need request user input in several of screens. follow design patterns while designing app , focusing on model-view-controller design pattern right now. focus on user registration , sign in screens explain scenario. have user registration screen , sign in page both share similar input fields such as: email , password

i have following classes far in order follow mvc pattern:

model classes: user.swift

view classes: userview.swift

controller classes: userregistrationviewcontroller.swift, signinviewcontroller.swift

the issue having in terms of design in each view controller class validating each input field using regex. can guess means have ended lot of repeated code in both view controllers. instance, validating email , password same way in both view controllers. thus, how should solve , still follow mvc? leaning towards having validator class several validator functions can called , reused each view controller , perhaps regex class contain regex only? or should type of properties file?

step , think little. regex functions do? validate , parse data. model (data storage) function? not really. view? not @ all. control? seems best fit. controller mediates between view objects , data model, , provides app control logic.

now, duplicate code problem. have various options dealing this.

one create common subclass view controllers provides regex support.

another approach create extension view controller class , put validation code there.

a third approach create validator class, , have view controllers have validator property (a "has a" relationship. view controller has validator manages validation it.) use blend. have subclass of uiviewcontroller has "plumbing" validator class.

i lean towards third approach. keeping validation functions out of view controller makes modular , more reusable. designing validator class (assuming approach take) think other use-cases validator class might useful, , try design accommodate wide range of use cases.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -