[swift-users] Member wise initializer doesn't work with default-initialized const properties
jens at mooseyard.com
Wed May 18 12:01:49 CDT 2016
> On May 17, 2016, at 7:48 AM, Neil Faiman via swift-users <swift-users at swift.org> wrote:
> “You can provide a default value for a stored property as part of its definition, as described in Default Property Values. You can also set and modify the initial value for a stored property during initialization. This is true even for constant stored properties, as described in Assigning Constant Properties During Initialization.” (Classes and Structures / Stored Properties)
You can assign the value of an as-yet-unassigned ‘let’ property, once. If that happens in the default initialization phase (before any initializer methods run), then you’ve used up that chance. The initializer would be setting a second value, which isn’t allowed.
Read up on the phases of initialization in the Swift book.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users