Swift class constants are mutable within the initialiser
✓ Published0🌍 Public
CColinEberhardt
Last edited Dec 3, 2014
Created on Dec 3, 2014
This example demonstrates that Swift class constants, declared with `let`, can be assigned multiple times within the initialiser, despite being immutable elsewhere. The code defines a `Bar` class with an uninitialized `myConstant` field, then sets it to 77 and 45 before calling `super.init()`, and finally reassigns it to 55 after that call. A `doSomething()` method shows that further mutation outside the initialiser is prohibited. The example is a raw Swift source file from a gist, run as a standalone script.
AI-generated description