         }
     }
     
+    private func snapshotForCurrentState() -> NSDiffableDataSourceSnapshot<CollectionSection, County> {
+        var snapshot = NSDiffableDataSourceSnapshot<CollectionSection, County>()
+        snapshot.appendSections([.counties])
+        if let searchText = searchController.searchBar.text, searchText.count > 0 {
+            snapshot.appendItems(spotlightSearchController.searchResults)
+        } else {
+            snapshot.appendItems(County.allCounties)
+        }
+        return snapshot
+    }
+    
     private func styleForTraitCollection(_ traitCollection: UITraitCollection) -> CountyCellDisplayStyle {
         return traitCollection.horizontalSizeClass == .regular ? .grid : .table
-    }
-}
-
-// MARK: UICollectionViewDataSource
-extension MasterViewController: UICollectionViewDataSource {
-    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return countiesToDisplay.count
-    }
-    
-    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-        let countyCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CountyCell", for: indexPath) as! CountyCell
-        countyCell.county = countiesToDisplay[indexPath.row]
-        countyCell.displayStyle = styleForTraitCollection(traitCollection)
-        return countyCell
     }
 }
 

    
    private func updateSearchResults(forSearchText searchText: String?) {
        spotlightSearchController.search(withQueryString: searchText ?? "") { [unowned self] in
            self.collectionView.reloadData()
        }
    }
}

class MasterViewController: UIViewController {
    @IBOutlet var collectionView: UICollectionView!
    @IBOutlet private var flowLayout: UICollectionViewFlowLayout!
    private var dataSource: UICollectionViewDiffableDataSource<CollectionSection, County>!
    var selectedCounty: County?
    var history: CountyHistory?
    private var spotlightSearchController = SpotlightSearchController()
    private lazy var searchController: UISearchController = {
        let searchController = UISearchController(searchResultsController: nil)
        searchController.obscuresBackgroundDuringPresentation = false
