From e461dae024d1dce355d35d3ccb3ab1c74f9447fe Mon Sep 17 00:00:00 2001 From: Aaron Date: Sat, 23 Jan 2021 16:30:33 -0500 Subject: [PATCH 01/15] Redesigned RPS class --- ProjectClock/MathExpressions.swift | 31 +++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/ProjectClock/MathExpressions.swift b/ProjectClock/MathExpressions.swift index 9fbc095..0a31d48 100644 --- a/ProjectClock/MathExpressions.swift +++ b/ProjectClock/MathExpressions.swift @@ -163,10 +163,19 @@ class RPS { case rock = "ROCK" case paper = "PAPER" case scissors = "SCISSORS" - - static func randomComputerChoice() -> Choice { - let choices: [Choice] = [.rock, .paper, .scissors] - return choices[Int.random(in: 0...2)] + } + + static func randomComputerChoice() -> Choice { + let choices: [Choice] = [.rock, .paper, .scissors] + return choices[Int.random(in: 0...2)] + } + + func playRPS(you: Choice, computer: Choice) -> Bool? { + if you == .rock && computer == .scissors { return true } + else if you == .paper && computer == .rock { return true} + else if you == .scissors && computer == .paper { return true } + else { + return playRPS(you: you, computer: RPS.randomComputerChoice()) } } @@ -186,18 +195,4 @@ class RPS { resultsLabel.text = playRPS(you: .scissors, computer: computerChoice) } */ - - func playRPS(you: Choice, computer: Choice) -> Bool? { - if you == computer { return nil } - else if you == .rock && computer == .scissors { return true } - else if you == .paper && computer == .rock { return false} - else if you == .scissors && computer == .paper { return true } - else { - let randomNum = Int.random(in: 0...2) - if randomNum == 0 { return false } - // DO THESE RETURN THE RIGHT THING? - else if randomNum == 1 { return false} - else { return false } - } - } } From 5800cd97746b589982127dc4c0d303ac66dae7b5 Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 16:47:17 -0500 Subject: [PATCH 02/15] RPS UI Design --- ProjectClock/Base.lproj/Main.storyboard | 79 +++++++++++++++++-------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index d87ddd9..15aba97 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -507,44 +507,71 @@ - + - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -696,7 +723,7 @@ - + From 219de54856e98ba2e26962592286b273b71204f9 Mon Sep 17 00:00:00 2001 From: Aaron Date: Sat, 23 Jan 2021 16:47:31 -0500 Subject: [PATCH 03/15] Adjusted RPS related actions --- ProjectClock/Base.lproj/Main.storyboard | 2 +- ProjectClock/MathExpressions.swift | 2 +- ProjectClock/NotificationLogic.swift | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index d87ddd9..7cbd5d4 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -696,7 +696,7 @@ - + diff --git a/ProjectClock/MathExpressions.swift b/ProjectClock/MathExpressions.swift index 0a31d48..5a8171a 100644 --- a/ProjectClock/MathExpressions.swift +++ b/ProjectClock/MathExpressions.swift @@ -175,7 +175,7 @@ class RPS { else if you == .paper && computer == .rock { return true} else if you == .scissors && computer == .paper { return true } else { - return playRPS(you: you, computer: RPS.randomComputerChoice()) + return false } } diff --git a/ProjectClock/NotificationLogic.swift b/ProjectClock/NotificationLogic.swift index 640a349..29a620c 100644 --- a/ProjectClock/NotificationLogic.swift +++ b/ProjectClock/NotificationLogic.swift @@ -15,10 +15,12 @@ func walkAction() { } func jumpAction() { - let rps = RPS() + } -func rpsAction() { +func rpsAction(choice: RPS.Choice) -> Bool? { + let rps = RPS() + return rps.playRPS(you: choice, computer: RPS.randomComputerChoice()) } From 5b576a7912a74061150555b6243533df32d2740a Mon Sep 17 00:00:00 2001 From: Aaron Date: Sat, 23 Jan 2021 16:49:05 -0500 Subject: [PATCH 04/15] Fixed storyboard --- ProjectClock/Base.lproj/Main.storyboard | 62 ++++++++++++------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index 15aba97..d23d9f4 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -512,13 +512,43 @@ + + + + + + + + + + + + + + + + + + - + @@ -542,36 +572,6 @@ - - - - - - - - - - - - - - - - - - From ff22e44140b253252c142cf933abdeff3503323f Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 16:54:34 -0500 Subject: [PATCH 05/15] Corrected error --- ProjectClock/Models.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectClock/Models.swift b/ProjectClock/Models.swift index cf1d8bc..7792d6f 100644 --- a/ProjectClock/Models.swift +++ b/ProjectClock/Models.swift @@ -32,7 +32,7 @@ struct WVM: Codable let wvms = [ WVM(name: "Factor", desc: "Factor a binomial"), WVM(name: "RPS", desc: "Win a game of rock paper scissors"), - WVM(name: "Smash", desc: "It'll never truns off"), + WVM(name: "Smash", desc: "It'll never turn off"), WVM(name: "Walk", desc: "Walk a few steps"), WVM(name: "Jump", desc: "Make a few jumps") ] From 2a9cb8e6775392278b7a55ebb4fd7bd622c8cfe0 Mon Sep 17 00:00:00 2001 From: Aaron Date: Sat, 23 Jan 2021 17:09:31 -0500 Subject: [PATCH 06/15] Theoretical RPS WVM completed --- .../AlarmActivationViewController.swift | 37 ++++++++++++++++++- ProjectClock/Base.lproj/Main.storyboard | 25 ++++++++++++- ProjectClock/TestingViewController.swift | 2 +- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/ProjectClock/AlarmActivationViewController.swift b/ProjectClock/AlarmActivationViewController.swift index 092de54..d976b31 100644 --- a/ProjectClock/AlarmActivationViewController.swift +++ b/ProjectClock/AlarmActivationViewController.swift @@ -13,12 +13,17 @@ class AlarmActivationViewController: UIViewController var timer: Timer? var currentAlarm: Alarm? - //Outlets + //Puzzle outlets @IBOutlet weak var puzzleView: UIView! @IBOutlet weak var puzzleQuestionLabel: UILabel! @IBOutlet weak var puzzleAnswerInput: UITextField! var puzzleAnswers: [Int] = [] + //RPS Outlets + @IBOutlet weak var rpsView: UIView! + @IBOutlet weak var rpsResult: UILabel! + + init?(coder: NSCoder, currentAlarm: Alarm) { self.currentAlarm = currentAlarm @@ -35,6 +40,7 @@ class AlarmActivationViewController: UIViewController super.viewDidLoad() //Hide all inactive wakemethods puzzleView.isHidden = true + rpsView.isHidden = true timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(AlarmActivationViewController.playSound), userInfo: nil, repeats: true) setAlarmType() @@ -61,6 +67,10 @@ class AlarmActivationViewController: UIViewController puzzleView.isHidden = false case "Smash": print("") + case "RPS": + rpsView.isHidden = false + //Get Choice here + //rpsAction(choice: choice) default: print("Invalid alarm type") } @@ -78,6 +88,31 @@ class AlarmActivationViewController: UIViewController } } + //Gets RPS choice + @IBAction func rockChoice(_ sender: Any) { + if rpsAction(choice: .rock)! { + endAlarm() + } else { + rpsResult.text = "Paper: You lost, try again" + } + } + @IBAction func paperChoice(_ sender: Any) { + if rpsAction(choice: .paper)! { + endAlarm() + } else { + rpsResult.text = "Scissors: You lost, try again" + } + } + @IBAction func scissorChoice(_ sender: Any) { + if rpsAction(choice: .scissors)! { + endAlarm() + } else { + rpsResult.text = "Rock: You lost, try again" + } + } + + + //Standard way to turn off and close the alarm func endAlarm() { timer?.invalidate() diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index d23d9f4..599710b 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -553,27 +553,43 @@ - + + - + @@ -593,6 +609,8 @@ + + @@ -807,6 +825,9 @@ + + + diff --git a/ProjectClock/TestingViewController.swift b/ProjectClock/TestingViewController.swift index 4738236..d0b2444 100644 --- a/ProjectClock/TestingViewController.swift +++ b/ProjectClock/TestingViewController.swift @@ -58,7 +58,7 @@ class TestingViewController: UIViewController @IBAction func addAlarm(_ sender: Any) { let (h, m, _) = Date().getHMS() - Alarms.fromLocal().apply { $0.list.append(Alarm(hour: h, minute: m, text: "Test alarm - \(h * m)", wakeMethod: wvms[0], lastActivate: Date().added(.minute, -1))) }.localSave() + Alarms.fromLocal().apply { $0.list.append(Alarm(hour: h, minute: m, text: "Test alarm - \(h * m)", wakeMethod: wvms[1], lastActivate: Date().added(.minute, -1))) }.localSave() } @IBAction func deleteAlarm(_ sender: Any) From e6817bd795a6fb649ad3a2f25784def9fa1764f7 Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 17:34:28 -0500 Subject: [PATCH 07/15] Created Stopwatch controller and adjusted/linked tab bar --- ProjectClock.xcodeproj/project.pbxproj | 4 ++++ ProjectClock/Base.lproj/Main.storyboard | 28 ++++++++++++++++++---- ProjectClock/StopwatchViewController.swift | 19 +++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 ProjectClock/StopwatchViewController.swift diff --git a/ProjectClock.xcodeproj/project.pbxproj b/ProjectClock.xcodeproj/project.pbxproj index f9fa29e..95840b7 100644 --- a/ProjectClock.xcodeproj/project.pbxproj +++ b/ProjectClock.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 7C83963625AF375B0027A94C /* NotificationLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963525AF375B0027A94C /* NotificationLogic.swift */; }; 7C83963925AF68980027A94C /* TestingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C83963825AF68980027A94C /* TestingViewController.swift */; }; C7E638E825B88F8B00799512 /* MathExpressions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7E638E725B88F8B00799512 /* MathExpressions.swift */; }; + F0DF7C0725BCD9FC0064A26B /* StopwatchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DF7C0625BCD9FC0064A26B /* StopwatchViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -46,6 +47,7 @@ 7C83963525AF375B0027A94C /* NotificationLogic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationLogic.swift; sourceTree = ""; }; 7C83963825AF68980027A94C /* TestingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestingViewController.swift; sourceTree = ""; }; C7E638E725B88F8B00799512 /* MathExpressions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MathExpressions.swift; sourceTree = ""; }; + F0DF7C0625BCD9FC0064A26B /* StopwatchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StopwatchViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -92,6 +94,7 @@ 4FD642DF25B4D5F30069171E /* AlarmActivationViewController.swift */, 4FD642D225B48C380069171E /* AlarmActivator.swift */, 4FF0684425A5F18700304E6B /* Main.storyboard */, + F0DF7C0625BCD9FC0064A26B /* StopwatchViewController.swift */, 7C83963525AF375B0027A94C /* NotificationLogic.swift */, 4F98955125A9260400F51321 /* Net.swift */, 4F509BD125AE22D100726227 /* Models.swift */, @@ -187,6 +190,7 @@ 4F98955225A9260400F51321 /* Net.swift in Sources */, 7C83963925AF68980027A94C /* TestingViewController.swift in Sources */, 4FF0684325A5F18700304E6B /* AccountViewController.swift in Sources */, + F0DF7C0725BCD9FC0064A26B /* StopwatchViewController.swift in Sources */, 4FF0683F25A5F18700304E6B /* AppDelegate.swift in Sources */, 4FD642D325B48C380069171E /* AlarmActivator.swift in Sources */, 4FD642DB25B4B7F60069171E /* Utils.swift in Sources */, diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index 599710b..66054f6 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -198,7 +198,7 @@ - + @@ -268,7 +268,23 @@ - + + + + + + + + + + + + + + + + + @@ -615,7 +631,7 @@ - + @@ -632,6 +648,7 @@ + @@ -724,7 +741,7 @@ - + @@ -809,12 +826,13 @@ - + + diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift new file mode 100644 index 0000000..51dd620 --- /dev/null +++ b/ProjectClock/StopwatchViewController.swift @@ -0,0 +1,19 @@ +// +// StopwatchViewController.swift +// ProjectClock +// +// Created by Dallon Archibald on 1/23/21. +// + +import UIKit + +class StopwatchViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + +} From 74c2c76af9427491b496b83537f25de347c46516 Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 17:58:27 -0500 Subject: [PATCH 08/15] Implemented and linked UI elements --- ProjectClock/Base.lproj/Main.storyboard | 104 ++++++++++++++++++++- ProjectClock/StopwatchViewController.swift | 9 ++ 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index 66054f6..069770f 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -4,6 +4,7 @@ + @@ -277,14 +278,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -837,6 +936,9 @@ + + + diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift index 51dd620..b747236 100644 --- a/ProjectClock/StopwatchViewController.swift +++ b/ProjectClock/StopwatchViewController.swift @@ -9,6 +9,15 @@ import UIKit class StopwatchViewController: UIViewController { + @IBOutlet weak var hourLabel: UILabel! + @IBOutlet weak var minuteLabel: UILabel! + @IBOutlet weak var secondLabel: UILabel! + + @IBOutlet weak var startButton: UIButton! + @IBOutlet weak var stopButton: UIButton! + @IBOutlet weak var resetButton: UIButton! + @IBOutlet weak var lapButton: UIButton! + override func viewDidLoad() { super.viewDidLoad() From 34cc04cd6377677a5a44ad4125f80cdacf3f611e Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 18:41:31 -0500 Subject: [PATCH 09/15] Table Cell Prototype --- ProjectClock/Base.lproj/Main.storyboard | 175 +++++++++++---------- ProjectClock/StopwatchViewController.swift | 22 ++- 2 files changed, 114 insertions(+), 83 deletions(-) diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index 069770f..18a6b08 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -279,95 +279,105 @@ - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + @@ -379,6 +389,7 @@ + diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift index b747236..49d8379 100644 --- a/ProjectClock/StopwatchViewController.swift +++ b/ProjectClock/StopwatchViewController.swift @@ -18,11 +18,31 @@ class StopwatchViewController: UIViewController { @IBOutlet weak var resetButton: UIButton! @IBOutlet weak var lapButton: UIButton! + @IBOutlet weak var tableView: UITableView! + + var hours = 0 + var minutes = 0 + var seconds = 0 + + var timer = Timer() + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } - } + +extension StopwatchViewController: UITableViewDelegate, UITableViewDataSource { + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 100 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "lapCell", for: indexPath) + cell.textLabel?.text = "I am a lap cell \(indexPath.row + 1)" + return cell + } +} From 4ff0455afd4f3bf88724f36500864283302a59fa Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 18:44:16 -0500 Subject: [PATCH 10/15] Edited table view display --- ProjectClock/StopwatchViewController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift index 49d8379..bc0fe9b 100644 --- a/ProjectClock/StopwatchViewController.swift +++ b/ProjectClock/StopwatchViewController.swift @@ -24,6 +24,7 @@ class StopwatchViewController: UIViewController { var minutes = 0 var seconds = 0 + var lappedTimes: [String] = ["1", "2", "3"] var timer = Timer() override func viewDidLoad() { @@ -37,12 +38,12 @@ class StopwatchViewController: UIViewController { extension StopwatchViewController: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 100 + return lappedTimes.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "lapCell", for: indexPath) - cell.textLabel?.text = "I am a lap cell \(indexPath.row + 1)" + cell.textLabel?.text = lappedTimes[indexPath.row] return cell } } From 26c2b2832e12628ce4551c6edcec531000501346 Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 18:50:10 -0500 Subject: [PATCH 11/15] Testing/Displaying Count --- ProjectClock/Base.lproj/Main.storyboard | 12 ++++++++++++ ProjectClock/StopwatchViewController.swift | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index 18a6b08..cd44af6 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -326,6 +326,9 @@ + + + diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift index bc0fe9b..a930114 100644 --- a/ProjectClock/StopwatchViewController.swift +++ b/ProjectClock/StopwatchViewController.swift @@ -24,7 +24,7 @@ class StopwatchViewController: UIViewController { var minutes = 0 var seconds = 0 - var lappedTimes: [String] = ["1", "2", "3"] + var lappedTimes: [String] = [] var timer = Timer() override func viewDidLoad() { @@ -32,7 +32,23 @@ class StopwatchViewController: UIViewController { // Do any additional setup after loading the view. } - + + @IBAction func start(_ sender: UIButton) { + timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(count), userInfo: nil, repeats: true) + } + + + @IBAction func stop(_ sender: UIButton) { + } + @IBAction func reset(_ sender: UIButton) { + } + @IBAction func lap(_ sender: UIButton) { + } + + @objc fileprivate func count() { + seconds += 1 + print(seconds) + } } extension StopwatchViewController: UITableViewDelegate, UITableViewDataSource { From e0c0e24188b17be61291215fb3f476f0f974109e Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 19:18:50 -0500 Subject: [PATCH 12/15] Configured Basic Functionalities and Updated Table Functions --- ProjectClock/StopwatchViewController.swift | 47 +++++++++++++++++----- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift index a930114..ca284c4 100644 --- a/ProjectClock/StopwatchViewController.swift +++ b/ProjectClock/StopwatchViewController.swift @@ -37,17 +37,37 @@ class StopwatchViewController: UIViewController { timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(count), userInfo: nil, repeats: true) } - - @IBAction func stop(_ sender: UIButton) { - } - @IBAction func reset(_ sender: UIButton) { - } - @IBAction func lap(_ sender: UIButton) { - } - @objc fileprivate func count() { seconds += 1 - print(seconds) + if seconds == 60 { + minutes += 1 + seconds = 0 + } + if minutes == 60 { + hours += 1 + minutes = 0 + } + if hours == 24 { + timer.invalidate() + } + secondLabel.text = "\(seconds)" //if time, make it display 01, 02... + minuteLabel.text = minutes == 0 ? "00" : "\(minutes)" + hourLabel.text = hours == 0 ? "00" : "\(hours)" + } + + @IBAction func stop(_ sender: UIButton) { + timer.invalidate() + } + + @IBAction func reset(_ sender: UIButton) { + } + + @IBAction func lap(_ sender: UIButton) { + let currentTime = "\(hours):\(minutes):\(seconds)" + lappedTimes.append(currentTime) + + let indexPath = IndexPath(row: lappedTimes.count - 1, section: 0) + tableView.insertRows(at: [indexPath], with: .automatic) } } @@ -60,6 +80,15 @@ extension StopwatchViewController: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "lapCell", for: indexPath) cell.textLabel?.text = lappedTimes[indexPath.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) + } + } } From e18edd26d2e98c158b099f2235de834e07560fbf Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 19:49:34 -0500 Subject: [PATCH 13/15] Updated Display Time to be More Appealing --- ProjectClock/StopwatchViewController.swift | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift index ca284c4..797bba7 100644 --- a/ProjectClock/StopwatchViewController.swift +++ b/ProjectClock/StopwatchViewController.swift @@ -39,6 +39,7 @@ class StopwatchViewController: UIViewController { @objc fileprivate func count() { seconds += 1 + if seconds == 60 { minutes += 1 seconds = 0 @@ -50,9 +51,13 @@ class StopwatchViewController: UIViewController { if hours == 24 { timer.invalidate() } - secondLabel.text = "\(seconds)" //if time, make it display 01, 02... - minuteLabel.text = minutes == 0 ? "00" : "\(minutes)" - hourLabel.text = hours == 0 ? "00" : "\(hours)" + + if seconds >= 10 { secondLabel.text = "\(seconds)" } + else { secondLabel.text = "0\(seconds)" } + if minutes >= 10 { minuteLabel.text = "\(minutes)" } + else { minuteLabel.text = "0\(minutes)" } + if hours >= 10 { hourLabel.text = "\(hours)" } + else { hourLabel.text = "0\(hours)" } } @IBAction func stop(_ sender: UIButton) { @@ -63,7 +68,19 @@ class StopwatchViewController: UIViewController { } @IBAction func lap(_ sender: UIButton) { - let currentTime = "\(hours):\(minutes):\(seconds)" + var currentSec = "" + if seconds >= 10 { currentSec = "\(seconds)" } + else { currentSec = "0\(seconds)" } + + var currentMin = "" + if minutes >= 10 { currentMin = "\(minutes)" } + else { currentMin = "0\(minutes)" } + + var currentHour = "" + if hours >= 10 { currentHour = "\(hours)" } + else { currentHour = "0\(hours)" } + + let currentTime = "\(currentHour):\(currentMin):\(currentSec)" //CHECK THIS lappedTimes.append(currentTime) let indexPath = IndexPath(row: lappedTimes.count - 1, section: 0) From 1cd6e73ac4fa2d43438883ab881ddcad481e225e Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 20:26:33 -0500 Subject: [PATCH 14/15] Finished Everything - fix time display and hiding buttons --- ProjectClock/StopwatchViewController.swift | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift index 797bba7..a013ed7 100644 --- a/ProjectClock/StopwatchViewController.swift +++ b/ProjectClock/StopwatchViewController.swift @@ -30,11 +30,13 @@ class StopwatchViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view. + //lapButton.isHidden = true } @IBAction func start(_ sender: UIButton) { timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(count), userInfo: nil, repeats: true) + //startButton.isHidden = true + //lapButton.isHidden = false } @objc fileprivate func count() { @@ -49,7 +51,7 @@ class StopwatchViewController: UIViewController { minutes = 0 } if hours == 24 { - timer.invalidate() + resetTimes() } if seconds >= 10 { secondLabel.text = "\(seconds)" } @@ -62,9 +64,25 @@ class StopwatchViewController: UIViewController { @IBAction func stop(_ sender: UIButton) { timer.invalidate() + //startButton.isHidden = false } @IBAction func reset(_ sender: UIButton) { + resetTimes() + } + + func resetTimes() { + seconds = 0 + minutes = 0 + seconds = 0 + lappedTimes = [] + timer.invalidate() + secondLabel.text = "00" + minuteLabel.text = "00" + hourLabel.text = "00" + tableView.reloadData() + //startButton.isHidden = false + //lapButton.isHidden = true } @IBAction func lap(_ sender: UIButton) { From b71a2463c95e7a8cc7ddf73f47b6ab386d6d2aa8 Mon Sep 17 00:00:00 2001 From: Dallon Archibald Date: Sat, 23 Jan 2021 20:30:10 -0500 Subject: [PATCH 15/15] Linked Reference --- ProjectClock/StopwatchViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectClock/StopwatchViewController.swift b/ProjectClock/StopwatchViewController.swift index a013ed7..cfe64ec 100644 --- a/ProjectClock/StopwatchViewController.swift +++ b/ProjectClock/StopwatchViewController.swift @@ -3,7 +3,7 @@ // ProjectClock // // Created by Dallon Archibald on 1/23/21. -// +// Reference: https://youtu.be/H691qFRpaWA import UIKit