guillermomuntaner / Burritos

A collection of Swift Property Wrappers (formerly "Property Delegates")
MIT License
1.33k stars 43 forks source link

Lazy property wrapper doesn't work with closures #21

Open mmdock opened 3 years ago

mmdock commented 3 years ago

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