Skip to content

Instantly share code, notes, and snippets.

@swdevbali
Created November 1, 2021 22:26
Show Gist options
  • Save swdevbali/813af97fcba5c2721e2ce2870c278dd8 to your computer and use it in GitHub Desktop.
Save swdevbali/813af97fcba5c2721e2ce2870c278dd8 to your computer and use it in GitHub Desktop.
//class version
class TomatoClass {
var name: String
var state: Bool // true=active, false=pause
var start_time: Date
var finish_time: Date?
var elapsed_time: TimeInterval?
init(name: String, state: Bool, start_time: Date){
self.name = name
self.state = state
self.start_time = start_time
}
func toggle() {
state = !state
}
func finish() {
finish_time = Date()
state = false
elapsed_time = start_time.distance(to: finish_time ?? Date())
}
}
print("Class version")
var classTomato = TomatoClass(name: "This is class version of tomato struct", state: true, start_time: Date())
print(classTomato.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment