Last active
June 19, 2019 11:35
-
-
Save NavdeepSinghh/434a35d2ff4b6496c9d50142c4242fea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct Counter { | |
private var start: Double? | |
private var totalCount: Double = 0 | |
private var incrementBy: Double | |
var isCounterRunning: Bool { | |
return start != nil | |
} | |
var incrementedCount: Double { | |
return totalCount + (start.map{ _ in incrementBy} ?? 0) | |
} | |
mutating func startCounter() { | |
start = 1 | |
} | |
mutating func pauseCounter() { | |
totalCount = incrementedCount | |
start = nil | |
} | |
mutating func resetCounter() { | |
start = nil | |
totalCount = 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment