Skip to content

Instantly share code, notes, and snippets.

@zwaldowski
Created August 19, 2014 13:12
Show Gist options
  • Save zwaldowski/18d4849f71ea8a665151 to your computer and use it in GitHub Desktop.
Save zwaldowski/18d4849f71ea8a665151 to your computer and use it in GitHub Desktop.
class MyClass {
lazy var property: String! = {
println("Inside the initializer!")
return "Fallback"
}()
}
let obj = MyClass()
println("property: \(obj.property)")
obj.property = "Foo"
println("property: \(obj.property)")
obj.property = nil
println("property: \(obj.property)")
/**
Console output:
Inside the initializer!
property: Fallback
property: Foo
Inside the initializer!
property: Fallback
*/
@a2
Copy link

a2 commented Aug 19, 2014

y u use tab literals!? i thought you knew better!

@zwaldowski
Copy link
Author

Historical note: this is no longer the Swift Lazy behavior.

@zwaldowski
Copy link
Author

@a2: I reformatted it in GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment