From bd5b5704d17c23925b9e86edcc94870bffccf729 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Wed, 27 Jan 2021 17:41:17 -0500 Subject: [PATCH] [+] Add comments to AlarmActivationViewController --- .../AlarmActivationViewController.swift | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/ProjectClock/AlarmActivationViewController.swift b/ProjectClock/AlarmActivationViewController.swift index b4ab766..5527ad5 100644 --- a/ProjectClock/AlarmActivationViewController.swift +++ b/ProjectClock/AlarmActivationViewController.swift @@ -8,28 +8,34 @@ import UIKit import AVFoundation +/** + View controlling alarm activation and dismissal + */ class AlarmActivationViewController: UIViewController { var timer: Timer? var currentAlarm: Alarm? - //Puzzle outlets + // Puzzle outlets @IBOutlet weak var puzzleView: UIView! @IBOutlet weak var puzzleQuestionLabel: UILabel! @IBOutlet weak var puzzleAnswerInput: UITextField! var puzzleAnswers: [Int] = [] - //RPS Outlets + // RPS Outlets @IBOutlet weak var rpsView: UIView! @IBOutlet weak var rpsResult: UILabel! - //Shake Outlets + // Shake Outlets @IBOutlet weak var shakeView: UIView! - //Other Outlets + // Other Outlets @IBOutlet weak var timeLabel: UILabel! @IBOutlet weak var dateLabel: UILabel! + /** + Constructor to receive alarm data from segue + */ init?(coder: NSCoder, currentAlarm: Alarm) { self.currentAlarm = currentAlarm @@ -37,10 +43,14 @@ class AlarmActivationViewController: UIViewController super.init(coder: coder) } - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } + /** + Unused init + */ + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } + /** + Called when the alarm activates + */ override func viewDidLoad() { super.viewDidLoad() @@ -61,19 +71,26 @@ class AlarmActivationViewController: UIViewController runAlarm() } + /** + Play alarm sound + */ @objc func playSound() { AudioServicesPlayAlertSound(currentAlarm!.alarmTone) AudioServicesPlayAlertSound(kSystemSoundID_Vibrate) } + /** + Run alarm dismissal logic + */ func runAlarm() { if let alarm = currentAlarm { - switch alarm.wakeMethod.name { + switch alarm.wakeMethod.name + { case "Walk": walkAction() case "Jump": @@ -99,7 +116,9 @@ class AlarmActivationViewController: UIViewController } } - //Verfies and ends factoring WVM + /** + Verfies and ends factoring WVM + */ @IBAction func checkBinomialSolution(_ sender: Any) { if let input = puzzleAnswerInput.text { if let numericalInput = Int(input) { @@ -110,7 +129,9 @@ class AlarmActivationViewController: UIViewController } } - //Gets RPS choice + /** + Gets RPS choice + */ @IBAction func rockChoice(_ sender: Any) { if rpsAction(choice: .rock)! { endAlarm() @@ -118,7 +139,6 @@ class AlarmActivationViewController: UIViewController rpsResult.text = "Paper: You lost, try again" } } - @IBAction func paperChoice(_ sender: Any) { if rpsAction(choice: .paper)! { endAlarm() @@ -134,10 +154,11 @@ class AlarmActivationViewController: UIViewController } } - - - //Standard way to turn off and close the alarm - func endAlarm() { + /** + Standard way to turn off and close the alarm + */ + func endAlarm() + { timer?.invalidate() print("Alarm solved") dismiss(animated: true, completion: nil)