Skip to content

Instantly share code, notes, and snippets.

@michzio
Last active May 3, 2020 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michzio/c7c15a2eae617cb654e5f9bd773ab1db to your computer and use it in GitHub Desktop.
Save michzio/c7c15a2eae617cb654e5f9bd773ab1db to your computer and use it in GitHub Desktop.
class CollectionViewController<Section, Item>: UIViewController, UICollectionViewDelegate
where Section : Hashable & CaseIterable, Item : Hashable {
// MARK: - Injections
var layout: UICollectionViewLayout! = nil
var snapshot : NSDiffableDataSourceSnapshot<Section, Item>! = nil
var content: ((_ indexPath: IndexPath, _ item: Item) -> AnyView)! = nil
var supplementaryKinds: [String]! = nil
var supplementaryContent: ((_ kind: String, _ indexPath: IndexPath, _ item: Item?) -> AnyView)? = nil
// MARK: - Properties
private(set) var dataSource: UICollectionViewDiffableDataSource<Section, Item>!
private let diffQueue = DispatchQueue.global(qos: .background)
// MARK: - Views
lazy var collectionView: UICollectionView = {
let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
collectionView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
collectionView.backgroundColor = .clear
return collectionView
}()
// MARK: - Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
configureCollectionView()
configureDataSource()
// load initial data
reloadDataSource(animating: false)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment