Skip to content

Instantly share code, notes, and snippets.

@PeteC
Last active August 29, 2015 14:05
Show Gist options
  • Save PeteC/2e43e5b50a536af4b4f1 to your computer and use it in GitHub Desktop.
Save PeteC/2e43e5b50a536af4b4f1 to your computer and use it in GitHub Desktop.
class MyClass {
var myNumber: Int {
willSet {
println("Will set to \(newValue) in the super class")
}
}
var myString: String
init(myNumber: Int, myString: String) {
self.myNumber = myNumber
self.myString = myString
}
}
class MySubClass: MyClass {
override var myNumber: Int {
willSet {
println("Will set to \(newValue) in the subclass")
}
}
override var myString: String {
willSet {
println("Will set myString to \(newValue) in the subclass")
}
}
}
let thing = MySubClass(myNumber: 1, myString: "Hello")
thing.myNumber = 2
thing.myString = "Goodbye"
/*
Outputs
Will set to 2 in the subclass
Will set to 2 in the super class
Will set myString to Goodbye in the subclass
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment