Last active
August 29, 2015 14:20
-
-
Save bjhomer/2f3dab6fbbdb1727c0b7 to your computer and use it in GitHub Desktop.
Magical initializer delegation
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 Top { | |
| let x: Int | |
| init() { x = 3; println("Top.init") } | |
| } | |
| class Bottom: Top { | |
| var z: String | |
| // This doesn't call `super.init`, but Top.init still runs. Why? | |
| init(dummy: Bool) { z = "hi" } | |
| } | |
| let b = Bottom(dummy: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that if a superclass has only one designated initializer, and it takes no parameters, then
super.initis implicitly called.