today saw code confused me:
lazy var variable = {......}()
i hope can explain me usage of lazy
.
lazy var variable: class = { <initialisation> return <resulting object> }()
is equivalent to:
var _variable: class? var variable: class { get{ if _variable == nil { <initialisation> _variable = <resulting object> } return _variable! } }
in short: initialises object when needed
Comments
Post a Comment