Created
November 1, 2021 22:26
-
-
Save swdevbali/813af97fcba5c2721e2ce2870c278dd8 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
//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