Created
April 5, 2020 13:11
-
-
Save tifoaudii/bc5793c1d1ed872d7298539fbe32eb69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
movieDataSource = UICollectionViewDiffableDataSource<MovieSection, Movie>(collectionView: movieCollectionView, cellProvider: { (collectionView, indexPath, movie) -> UICollectionViewCell? in | |
let movieSections = MovieSection.allCases[indexPath.section] | |
switch movieSections { | |
case .topRated: | |
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TopRatedMovieCell.cellIdentifier, for: indexPath) as? TopRatedMovieCell else { | |
return TopRatedMovieCell() | |
} | |
cell.movie = movie | |
return cell | |
case .onGoing: | |
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: OnGoingMovieCell.cellIdentifier, for: indexPath) as? OnGoingMovieCell else { | |
return OnGoingMovieCell() | |
} | |
cell.movie = movie | |
return cell | |
case .upcoming: | |
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: UpcomingMovieCell.cellIdentifier, for: indexPath) as? UpcomingMovieCell else { | |
return UpcomingMovieCell() | |
} | |
cell.movie = movie | |
return cell | |
case .popular: | |
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PopularMovieCell.cellIdentifier, for: indexPath) as? PopularMovieCell else { | |
return PopularMovieCell() | |
} | |
cell.movie = movie | |
return cell | |
} | |
}) | |
movieDataSource?.supplementaryViewProvider = { | |
(collectionView, kind, indexPath) -> UICollectionReusableView? in | |
guard let supplementaryView = collectionView.dequeueReusableSupplementaryView( | |
ofKind: kind, | |
withReuseIdentifier: HeaderView.reuseIdentifier, | |
for: indexPath) as? HeaderView else { fatalError("Cannot create header view") } | |
supplementaryView.label.text = MovieSection.allCases[indexPath.section].rawValue | |
return supplementaryView | |
} | |
movieDataSource?.apply(generateSnapshot(), animatingDifferences: false, completion: nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment