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 make your code more readable and avoid clutter.
In this section, you will organize four classes: ExploreViewController
, RestaurantListViewController
, LocationViewController
, and MapViewController
. You will then segregate blocks of related code using extensions. You'll begin with the ExploreViewController
class in the next section.
Refactoring the ExploreViewController class
In this section, you will divide the code in ExploreViewController.swift
into distinct sections using extensions. Follow these steps:
- Click
ExploreViewController.swift
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...