Skip to content

Instantly share code, notes, and snippets.

@hsleedevelop
Last active August 17, 2022 05:55
Show Gist options
  • Save hsleedevelop/46235610fd9e4259374b5186279e0f83 to your computer and use it in GitHub Desktop.
Save hsleedevelop/46235610fd9e4259374b5186279e0f83 to your computer and use it in GitHub Desktop.
TableView Template
typealias DataSource = UITableViewDiffableDataSource<Int, String>
typealias SnapShot = NSDiffableDataSourceSnapshot<Int, String>
private var dataSource: DataSource!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
setupTableView()
setupDataSource()
fetchData()
}
/// Setup table view.
private func setupTableView() {
tableView.backgroundColor = .clear
tableView.separatorStyle = .none
tableView.rowHeight = UITableView.automaticDimension
tableView.allowsSelection = true
tableView.tableFooterView = .init(frame: .init(x: 0, y: 0, width: 0, height: 50))
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "CellIdentifier")
}
private func setupDataSource() {
dataSource = DataSource(tableView: tableView, cellProvider: { tableView, indexPath, menuCase in
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
return cell
})
}
private func fetchData() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment