Series: Refactoring to Coordinators

Refactoring to Coordinators

Soroush Khanlou joins us again to help us refactor an existing application from Storyboards into the Coordinators pattern. Coordinators can help untangle view controller transition logic into a better design that is more reusable and more testable. Based on Soroush's blog post on the topic, we discuss the pros and cons of this approach and how it can improve your application architecture.

Length: about 1 hour

Installments

1. Why Coordinators?

Subscribers only

What is the Coordinators pattern, and why is it useful? Soroush and Ben discuss this and then get started refactoring an existing application that uses Storyboards into using Coordinators. We implement our first AppCoordinator and wire it up on launch.

2. Handling Actions from Users

Subscribers only

In this episode, Soroush and Ben create the first delegate for a view controller in order to pull out the behavior a user might trigger by interacting with the view controller. This delegate conformance is added to our coordinator so this flow logic is in one place (and not in the view controller).

3. Moving Review Logic

Subscribers only

Moving on to the next segue in our storyboard, this time Ben and Soroush tackle the Add Review flow. They discuss naming of delegates, the ideal place to perform logic such as preparing a model to be saved and where mutations to the model live. They end up with a view controller that is completely decoupled from the AddReviewViewController and a better picture of what the coordinator tends to look like.

4. Handling the Photo Transition

Subscribers only

This episode wraps up the refactoring series by implementing the transition to the PhotosViewController. Ben and Soroush talk about the overall process and benefits of coordinators as a pattern to clean up view controllers and organize logic around how your app is stitched together.