Last active
February 8, 2020 00:15
-
-
Save pranjalsatija/256d4bda2bb15d2019df415e9ed9c9f5 to your computer and use it in GitHub Desktop.
A simple example that shows how to use UITableViewDiffableDataSource.
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
typealias SectionType: Hashable // The type you're using to identify sections. | |
typealias DataType: Hashable // The type of the data you're displaying. | |
let dataSource = UITableViewDiffableDataSource<SectionType, DataType>( | |
tableView: tableView, | |
cellProvider: {(tableView, indexPath, data) in | |
// construct and return a cell here | |
} | |
) | |
tableView.dataSource = dataSource | |
tableView.delegate = self | |
var snapshot = NSDiffableDataSourceSnapshot<SectionType, DataType>() | |
snapshot.appendSections(sections) // Where sections is an array of SectionTypes that uniquely identify each section. | |
sections.forEach { snapshot.appendItems($0.items, toSection: $0 } | |
dataSource.apply(snapshot, animatingDifferences: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment