Created
January 17, 2016 16:07
-
-
Save hanawat/3b278523b3fe3e8478d1 to your computer and use it in GitHub Desktop.
Struct is the value type, but it's possible to change the property. *It's against a policy.
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 Date { | |
var year, month, day: Int | |
init(year: Int, month: Int, day: Int) { | |
self.year = year | |
self.month = month | |
self.day = day | |
} | |
mutating func increment(year year: UInt) { | |
self.year += Int(year) | |
} | |
} | |
var date = Date(year: 2016, month: 1, day: 18) | |
print("This year is \(date.year).") // This year is 2016. | |
date.increment(year: 1) | |
print("Next year is \(date.year).") // Next year is 2017. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment