Struct lazy Variable doubt


(Pritesh Nandgaonkar) #1

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.

<img src=’/uploads/default/original/1X/a0835f803d2d756e2cb20836413a360e969d250e.png’ width=‘690’ height=‘194’>

···

--
Pritesh Nandgaonkar
Department of Electrical Engineering
IIT Bomba


(Zhao Xin) #2

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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-users