Episode #272

Handling the Photo Transition

Series: Refactoring to Coordinators

8 minutes
Published on May 19, 2017

This video is only available to subscribers. Get access to this video and 584 others.

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.

Episode Links

Adding the Photos Transition

The first step is to remove the segue. Then we can add a new method to our RestaurantViewControllerDelegate protocol to be called when the user taps on the photos cell:

protocol RestaurantViewControllerDelegate : class {
    func addReviewTapped(_ vc: RestaurantViewController)
    func photosTapped(_ vc: RestaurantViewController)
}

We need to call this when the user taps on that cell, but that was previously done by the storyboard directly. We need to handle this action manually now:

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.section == Sections.info.rawValue && indexPath.row == 1 {
            restaurantDelegate?.photosTapped(self)
        } else {
            // nada
        }
    }

Add Conformance to AppCoordinator

We added a method to the protocol, so we need to update our coordinator to implement this method.

func photosTapped(_ vc: RestaurantViewController) {
    let photosVC = PhotosViewController.makeFromStoryboard()
    photosVC.restaurantID = vc.restaurantID
    navigationController.pushViewController(photosVC, animated: true)
}

This episode uses Ios 10.3, Xcode 8.3.