Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Inconsistency in lazy variable initialization between static and instance properties in Swift

$
0
0
struct MyStruct {    static var x = myX()    lazy var y = myY()}func myX() -> String {    print("myX is running")    return ""}func myY() -> String {    print("myY is running")    return ""}MyStruct.x = "X"var myStruct = MyStruct()myStruct.y = "Y"print("Done")

prints:

myX is running
Done

In other words static lazy variable gets initialized just before assigning, while instance property is just assigned.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>