From 6df3790e5162642d36a9f867f69516336cded465 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sun, 24 Jan 2021 09:10:59 -0500 Subject: [PATCH] [+] Add comments for table data source --- ProjectClock/StopwatchViewController.swift | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift index 9d2644b..ec0afda 100644 --- a/ProjectClock/StopwatchViewController.swift +++ b/ProjectClock/StopwatchViewController.swift @@ -90,24 +90,39 @@ class StopwatchViewController: UIViewController { } } -extension StopwatchViewController: UITableViewDelegate, UITableViewDataSource { - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { +/** + Table data source + */ +extension StopwatchViewController: UITableViewDelegate, UITableViewDataSource +{ + /** + Define row count + */ + func tableView(_ _: UITableView, numberOfRowsInSection _: Int) -> Int + { return lappedTimes.count } - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "lapCell", for: indexPath) - cell.textLabel?.text = lappedTimes[indexPath.row] + /** + Set cell at i + */ + func tableView(_ view: UITableView, cellForRowAt i: IndexPath) -> UITableViewCell + { + let cell = view.dequeueReusableCell(withIdentifier: "lapCell", for: i) + cell.textLabel?.text = lappedTimes[i.row] cell.selectionStyle = .none return cell } - func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { - if editingStyle == .delete { - lappedTimes.remove(at: indexPath.row) - - tableView.deleteRows(at: [indexPath], with: .automatic) + /** + Swipe left to delete cells at i + */ + func tableView(_ view: UITableView, commit: UITableViewCell.EditingStyle, forRowAt i: IndexPath) + { + if commit == .delete + { + lappedTimes.remove(at: i.row) + view.deleteRows(at: [i], with: .automatic) } } }