Extract Methods into the View Commands Protocol
Here’s the refactoring strategy we’ll use to move responsibilities into MVP:
-
Use the Extract Function refactoring to take commands issued to views, and move them into the View Commands protocol.
-
Use the Move Function refactoring to move functions that call these View Commands. We’ll move them from the view controller to the presenter.
Let’s find something that issues commands to UIKit views. Since we used MVVM before, most of these will be in the didSet observer of viewModel. Looking at the bottom, we see it calls updateActivityIndicator. Let’s start there.
| private func updateActivityIndicator() { |
| if viewModel.isActivityIndicatorShowing ... |
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.