Skip to content

Instantly share code, notes, and snippets.

@yannxou
Created December 24, 2014 09:33
Show Gist options
  • Save yannxou/73fba6a4df515462a041 to your computer and use it in GitHub Desktop.
Save yannxou/73fba6a4df515462a041 to your computer and use it in GitHub Desktop.
Swift: Computed lazy variable example
private lazy var debugLabel: UILabel = {
let label = UILabel(frame: CGRectMake(20, 20, 200, 20))
label.textColor = UIColor.redColor()
label.backgroundColor = UIColor.whiteColor()
return label
}() // the parentheses tells swift to use the return value of the closure, not the closure itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment