[swift-users] lazy initialisation

J.E. Schotsman jeschot at xs4all.nl
Mon Jul 4 14:35:17 CDT 2016

> On 04 Jul 2016, at 21:12, Mark Dalrymple <markd at borkware.com> wrote:
> lazy var c:Int = {return self.a * self.b}()
> It's in a closure, so need to explicitly reference self.

Oh of course, I got tripped up by the similarity of TestStruct1 and TestStruct2.
Problem solved.

BTW this compiles:

			struct TestStruct2
				lazy var c:Int = {return self.d}()
				lazy var d:Int = {return self.c}()

and causes a stack overflow:

var x = TestStruct2()
let y = x.c

More information about the swift-users mailing list