[O] Optimize stopwatch implementation
This commit is contained in:
@@ -360,8 +360,8 @@
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00:00" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="55a-Ig-Fri" customClass="StopwatchText" customModule="ProjectClock" customModuleProvider="target">
|
||||
<rect key="frame" x="52.5" y="109" width="309" height="95.5"/>
|
||||
<fontDescription key="fontDescription" type="system" weight="ultraLight" pointSize="80"/>
|
||||
<rect key="frame" x="51" y="109" width="312.5" height="95.5"/>
|
||||
<fontDescription key="fontDescription" type="system" weight="thin" pointSize="80"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
@@ -390,6 +390,7 @@
|
||||
<outlet property="startButton" destination="Jse-AL-cOs" id="iq2-xE-Nir"/>
|
||||
<outlet property="stopButton" destination="O4A-eq-kEz" id="dd7-v0-fqc"/>
|
||||
<outlet property="tableView" destination="O7B-Tj-vT0" id="kfu-vG-sgE"/>
|
||||
<outlet property="timeLabel" destination="55a-Ig-Fri" id="8eb-Ow-UF1"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="ZlX-5W-Pjn" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
|
||||
@@ -9,9 +9,7 @@ import UIKit
|
||||
|
||||
class StopwatchViewController: UIViewController {
|
||||
|
||||
@IBOutlet weak var hourLabel: UILabel!
|
||||
@IBOutlet weak var minuteLabel: UILabel!
|
||||
@IBOutlet weak var secondLabel: UILabel!
|
||||
@IBOutlet weak var timeLabel: UILabel!
|
||||
|
||||
@IBOutlet weak var startButton: UIButton!
|
||||
@IBOutlet weak var stopButton: UIButton!
|
||||
@@ -54,12 +52,7 @@ class StopwatchViewController: UIViewController {
|
||||
resetTimes()
|
||||
}
|
||||
|
||||
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)" }
|
||||
timeLabel.text = String(format: "%02i:%02i:%02i", hours, minutes, seconds)
|
||||
}
|
||||
|
||||
@IBAction func stop(_ sender: UIButton) {
|
||||
@@ -77,29 +70,14 @@ class StopwatchViewController: UIViewController {
|
||||
seconds = 0
|
||||
lappedTimes = []
|
||||
timer.invalidate()
|
||||
secondLabel.text = "00"
|
||||
minuteLabel.text = "00"
|
||||
hourLabel.text = "00"
|
||||
timeLabel.text = "00:00:00"
|
||||
tableView.reloadData()
|
||||
//startButton.isHidden = false
|
||||
//lapButton.isHidden = true
|
||||
}
|
||||
|
||||
@IBAction func lap(_ sender: UIButton) {
|
||||
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)
|
||||
lappedTimes.append(String(format: "%02i:%02i:%02i", hours, minutes, seconds))
|
||||
|
||||
let indexPath = IndexPath(row: lappedTimes.count - 1, section: 0)
|
||||
tableView.insertRows(at: [indexPath], with: .automatic)
|
||||
|
||||
Reference in New Issue
Block a user