Move Logic into the View Model
Most of the logic of this view controller is in the validateInputs method. For example, to see if the new password is too short, we have the following if statement:
| if newPasswordTextField.text?.count ?? 0 < 6 { |
Because UITextField’s text property is optional (due to legacy Objective-C code), this statement is extra fiddly. If the view model could express the content of each text field, we could separate this logic from UIKit.
So far, the interaction between the view model and the views has been one-way. Any changes to the view model cause the didSet observer to execute. This is one-way data binding: the views are bound to the view model.
We can expand ...
Get iOS Unit Testing by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.