Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Last active November 24, 2019 20:25
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 anupamchugh/baebc71889f4a7c7aabb7617bdc89c38 to your computer and use it in GitHub Desktop.
Save anupamchugh/baebc71889f4a7c7aabb7617bdc89c38 to your computer and use it in GitHub Desktop.
enum Section : CaseIterable {
case one
case two
}
class ViewController: UIViewController {
private let tableView = UITableView(frame: .zero, style: .insetGrouped)
private let cellReuseIdentifier = "cellId"
private lazy var dataSource = makeDataSource()
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self,forCellReuseIdentifier: cellReuseIdentifier)
view.addSubview(tableView) //additional autolayout setup in the source code
tableView.dataSource = dataSource
updateDataSource(animated: true)
}
func makeDataSource() -> UITableViewDiffableDataSource<Section, Movies> {
let reuseIdentifier = cellReuseIdentifier
return UITableViewDiffableDataSource(
tableView: tableView,
cellProvider: { tableView, indexPath, movie in
let cell = tableView.dequeueReusableCell(
withIdentifier: reuseIdentifier,
for: indexPath)
cell.textLabel?.text = movie.name
return cell
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment