Skip to content

Instantly share code, notes, and snippets.

@lilyball
Created November 22, 2018 00:44
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 lilyball/6078349909c11501d1e5318f4b27c813 to your computer and use it in GitHub Desktop.
Save lilyball/6078349909c11501d1e5318f4b27c813 to your computer and use it in GitHub Desktop.
struct Foo {
var fakeLazy: Int {
mutating get {
if let value = _fakeLazy { return value }
let value = calculateLazyValue()
_fakeLazy = value
return value
}
set {
_fakeLazy = newValue
}
}
private var _fakeLazy: Int?
private func calculateLazyValue() -> Int {
return 42
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment