Burritos icon indicating copy to clipboard operation
Burritos copied to clipboard

Lazy property wrapper doesn't work with closures

Open mmdock opened this issue 3 years ago • 0 comments

Simple playground test:

class Test {
    lazy var myLazyVar: Void = {
        print("crazy")
    }()
}

print("Initialize: ")
var test = Test()
print("call first")
test.myLazyVar

will print:

Initialize: 
call first
crazy

but then you have:

class Test {
    @Lazy var myLazyVar: Void = {
        print("crazy")
    }()
}

print("Initialize: ")
var test = Test()
print("call first")
test.myLazyVar

which will print:

Initialize: 
call first

mmdock avatar Feb 12 '21 21:02 mmdock