Replace String Literals to Use a View Model
The simplest place to begin a view model is to look for string literals. Search through ChangePasswordViewController, looking for double quotes. You will find:
- Various empty strings
- Alert messages
- The “OK” alert action label
The empty strings can remain. But let’s pull the other string literals into a view model. These strings don’t change, so we can start with a view model that doesn’t change state at first. Let’s begin by defining an empty view model. Add this file to the project:
| struct ChangePasswordViewModel { |
| } |
Then add it as a property in ChangePasswordViewController. In our case, we’re using a storyboard supporting iOS versions before ...
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.