Let's build a countdown app using diffable data source.
Our countdown app will start from 10 and decrement the initial value by 1 every second and add the new value as a row in the table view. Throughout the app we will make use of the snapshot as we update the table view and apply
the changes.
- Create an Xcode project named Countdown.
- Navigate to the ViewController.swift file and add the following:
enum Section {
case main
}
private var tableView: UITableView!
private var dataSource: UITableViewDiffableDataSource<Section, Int>!
private var timer: Timer!
private var startInterval = 10 // seconds
- Configure the table view.
- Configure the data source.
- Configure the timer.
- Add the
startCountdown
method. - Add the
decrementCounter
method. - Add the
ship
method. - Add a
refresh
bar button item to restart countdown.