[swift-users] Member wise initializer doesn't work with default-initialized const properties

Neil Faiman neil at faiman.org
Tue May 17 09:48:19 CDT 2016


> On May 17, 2016, at 7:03 AM, Jeremy Pereira <jeremy.j.pereira at googlemail.com> wrote:
> 
> 
>> On 16 May 2016, at 22:37, Neil Faiman via swift-users <swift-users at swift.org> wrote:
>> 
>> Using the default Swift with Xcode 7.3.1.
>> 
>> It appears that you cannot use the implicit memberwise initializer with a struct that has “let” properties with default values.
> 
> It’s not a default value, it is *the* value
> 
>> 
>> I don’t believe that the Apple _The Swift Programming Language_ mentions this restriction.
> 
> Chapter “The Basics”, section “Constants and Variables”
> 
> “The value of a constant cannot be changed once it is set”.

But:

“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)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160517/160d04a4/attachment.html>


More information about the swift-users mailing list