Organizing your code
As your programs become more complex, you will use extensions (covered in Chapter 8, Protocols, Extensions, and Error Handling) to organize your code. Extensions can help you to make code more readable and avoid clutter.
You will organize four classes: ExploreViewController, RestaurantListViewController, LocationViewController, and MapViewController. You will segregate blocks of related code using extensions. Let’s begin with the ExploreViewController class in the next section.
Refactoring the ExploreViewController class
You will divide the code in the ExploreViewController file into distinct sections using extensions. Follow these steps:
- Click the
ExploreViewControllerfile in the Project navigator. After the final curly brace, add the following:// MARK: Private Extension private extension ExploreViewController { // code goes here } // MARK: UICollectionViewDataSource extension ExploreViewController: UICollectionViewDataSource...