Last active
August 29, 2015 14:05
-
-
Save PeteC/2e43e5b50a536af4b4f1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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