Skip to content

Instantly share code, notes, and snippets.

@yas375

yas375/asd.swift Secret

Created December 23, 2015 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yas375/b0faae5c6200a7a9d402 to your computer and use it in GitHub Desktop.
Save yas375/b0faae5c6200a7a9d402 to your computer and use it in GitHub Desktop.
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