-
-
Save anupamchugh/baebc71889f4a7c7aabb7617bdc89c38 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
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