Model-View-Presenter, Form Validation, and a Unidirectional State Machine
As an exercise, I wrote a simple iOS scene transition from a login form (root view controller) to a success scene. I was experimenting with the Model-View-Presenter approach where view and presenter know each other, but communicate through protocols, so you program to an interface, not the implementation. I ended up using a simple state machine to represent the view’s state, and employed form validation that is represented in the types. I like how the result reads, so here’s a rundown of the exercise:
Better Form Model Validation
Earlier this month, I wrote about validating temporary models for forms. The validation returned .complete
or .incomplete
, which doesn’t help much when you want to show what did go wrong. So I came up with a richer validation syntax.
Validate Temporary Form Models
Ian Keen posted an article about type-safe temporary models. You would use them like scratch pad contexts in Core Data: in forms, you collect information into these temporary models and then generate your real objects from them.