Skip to content

Instantly share code, notes, and snippets.

@swdevbali
Created October 28, 2021 23:40
Show Gist options
  • Save swdevbali/a143eb3b249fb27b30184e290a8a2027 to your computer and use it in GitHub Desktop.
Save swdevbali/a143eb3b249fb27b30184e290a8a2027 to your computer and use it in GitHub Desktop.
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