Skip to content

Instantly share code, notes, and snippets.

@mthouser
Last active August 29, 2015 14:15
Show Gist options
  • Save mthouser/d96a74b927e4fbbc049c to your computer and use it in GitHub Desktop.
Save mthouser/d96a74b927e4fbbc049c to your computer and use it in GitHub Desktop.
Swift Presentation - Properties
protocol Exercising {
var heartRateIncrement : Int { get set }
func describe() -> String
}
class Sprint : Exercising {
var isWindSprint : Bool {
get {
return heartRateIncrement > 40
}
}
init() {
heartRateIncrement = 30
}
var heartRateIncrement : Int {
willSet (newIncrementor) {
println("About to set incrementor to \(newIncrementor)")
}
didSet {
println("Set incrementor to \(heartRateIncrement)")
}
}
func describe() -> String {
if isWindSprint {
return "Windsprinting"
} else {
return "Sprinting"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment