Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yfujiki/cf1d3779cc5b068b74d230f4ed543790 to your computer and use it in GitHub Desktop.
Save yfujiki/cf1d3779cc5b068b74d230f4ed543790 to your computer and use it in GitHub Desktop.
private lazy var compositionalLayout: UICollectionViewCompositionalLayout = {
let layout = UICollectionViewCompositionalLayout { [weak self]
(sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
switch Section(rawValue: sectionIndex) {
case .brandNames:
return self?.setupBrandNamesSection()
case .catFoods:
return self?.setupCatFoodsSection()
case .cats:
return self?.setupCatsSection()
case .none:
fatalError("Should not be none ")
}
}
return layout
}()
override func viewDidLoad() {
super.viewDidLoad()
...
collectionView.collectionViewLayout = compositionalLayout
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment