Skip to content

Instantly share code, notes, and snippets.

@elkraneo
Created May 26, 2015 15:20
Show Gist options
  • Save elkraneo/15b07b70ab11b3ad248e to your computer and use it in GitHub Desktop.
Save elkraneo/15b07b70ab11b3ad248e to your computer and use it in GitHub Desktop.
Overriding Properties
class Vehicle {
var currentSpeed = 0.0
var description: String {
return "traveling at \(currentSpeed) miles per hour"
}
func makeNoise() {
// do nothing - an arbitrary vehicle doesn't necessarily make a noise
}
}
class Car: Vehicle {
var gear = 1
override var description: String {
return super.description + " in gear \(gear)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment