-
-
Save yas375/b0faae5c6200a7a9d402 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nonLazyInitializationCalled = 0 | |
var lazyInitializationCalled = 0 | |
class Foo { | |
lazy var bar: String = { | |
lazyInitializationCalled += 1 | |
return "bar" | |
}() | |
var baz: String = { | |
nonLazyInitializationCalled += 1 | |
return "baz" | |
}() | |
} | |
lazyInitializationCalled // 0 | |
nonLazyInitializationCalled // 0 | |
let a = Foo() | |
lazyInitializationCalled // 0 | |
nonLazyInitializationCalled // 1 | |
a.bar | |
a.bar | |
a.baz | |
a.baz | |
lazyInitializationCalled // 1 | |
nonLazyInitializationCalled // 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment