Created
December 3, 2014 06:46
-
-
Save ColinEberhardt/36fe15ddee565af556b2 to your computer and use it in GitHub Desktop.
Swift class constants are mutable within the initialiser
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
| // A follow-up to the blog post here: | |
| // http://www.scottlogic.com/blog/2014/11/20/swift-initialisation.html | |
| class Foo { } | |
| class Bar: Foo { | |
| // no initial value set here | |
| let myConstant: Int | |
| override init() { | |
| // the constant needs an initial value - but | |
| // you can set it more than once! | |
| myConstant = 77 | |
| myConstant = 45 | |
| super.init() | |
| // you can set it here also | |
| myConstant = 55 // 55 | |
| println(myConstant) | |
| } | |
| func doSomething() { | |
| // but of course you cannot set it here! | |
| //myConstant = 66 | |
| } | |
| } | |
| let bar = Bar() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment