Last active
October 14, 2017 16:03
-
-
Save haydenholligan/dd69d5508f42bbc3dccd9dce11d7a461 to your computer and use it in GitHub Desktop.
A Swift struct for a Clock.
This file contains hidden or 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
//You can get the time components, but can only increment 1 second at a time. | |
struct Clock { | |
var seconds: Int = 0 { | |
didSet { | |
if seconds == 60 { | |
minutes += 1 | |
seconds = 0 | |
} | |
} | |
} | |
private(set) var minutes: Int = 0 { | |
didSet { | |
if minutes == 60 { | |
hours += 1 | |
minutes = 0 | |
} | |
} | |
} | |
private(set) var hours: Int = 0 | |
mutating func increment() { | |
seconds += 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment