[swift-users] Struct lazy Variable doubt

zh ao owenzx at gmail.com
Fri May 27 07:25:07 CDT 2016


I am a little odd about it too.

However,  if you give it a try, you will get the results.

var lazyStruct = lazyTest(lazyVariable: 5, someProperty: 6)

lazyStruct.lazyVariable // 5


var anotherStruct = lazyTest(lazyVariable:nil, someProperty: 7)

anotherStruct.lazyVariable // 10


​Everything works fine.​ If you give it a value, it just ignores the lazy
part. If you give it a nil, it works as you expect.

So initializer of Struct just adopts to a more flexible way, I think.

Zhaoxin


On Fri, May 27, 2016 at 5:15 PM, Pritesh Nandgaonkar via swift-users <
swift-users at swift.org> wrote:

> I have a struct with two properties one being Lazy and other being the
> normal one.When I try to initialise the struct the init function
> autosuggests the lazy property to be optional.Ideally the implementation
> should be such that, only non lazy and non computed properties must have
> been passed to the initialiser.Obviously this could be done through custom
> init implementation.But would like to know why its not handled.
>
> Have a look at the image for reference.
>
> [image: Inline image 2]
> --
> Pritesh Nandgaonkar
> Department of Electrical Engineering
> IIT Bomba
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160527/6d20bd2f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SwiftMailingListLazyStructDoubt.png
Type: image/png
Size: 57723 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160527/6d20bd2f/attachment.png>


More information about the swift-users mailing list