Skip to content

Instantly share code, notes, and snippets.

@hanawat
Created January 17, 2016 16:07
Show Gist options
  • Save hanawat/3b278523b3fe3e8478d1 to your computer and use it in GitHub Desktop.
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.
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