Created
October 28, 2021 23:40
-
-
Save swdevbali/a143eb3b249fb27b30184e290a8a2027 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
struct Tomato { | |
var name: String | |
var state: Bool // true=active, false=pause | |
var start_time: Date | |
var finish_time: Date | |
var elapsed_time: TimeInterval | |
mutating func toggle() { | |
state = !state | |
} | |
mutating func finish() { | |
finish_time = Date() | |
state = false | |
elapsed_time = start_time.distance(to: finish_time) | |
} | |
} | |
var tomato: Tomato = Tomato(name: "Composing Fundamental Swift Articles", state: true, start_time: Date(), finish_time: Date(), elapsed_time: 0) | |
print(tomato) | |
tomato.toggle() | |
print(tomato.state) | |
tomato.finish() | |
print(tomato.elapsed_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment