 // MARK: UICollectionViewDelegate
 extension MasterViewController: UICollectionViewDelegate {
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-        showCounty(countiesToDisplay[collectionView.indexPathsForSelectedItems!.first!.item], animated: true)
+        showCounty(dataSource.itemIdentifier(for: indexPath)!, animated: true)
         collectionView.deselectItem(at: indexPath, animated: false)
     }
 }

        super.viewDidLoad()
        navigationItem.searchController = searchController
        definesPresentationContext = true
    }
    
    override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {

        }
    }
    
    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
    }
}

