swift - Need clarification regarding computed properties -
this question has answer here:
i learning swift java/node.js background. after reading computed properties, wondering difference between following 2 uses:
private var _privatevariable: string = "test" var testvariable { return _privatevariable } var testvariable { get{ return _privatevariable } }
essentially, difference in usage between using getter get
keyword , returning variable within original variable declaration?
there no difference @ all. mere shortcut.
when write
var testvariable { get{ return _privatevariable } }
you can add setter @ point:
var testvariable { set{ _privatevariable = newvalue } get{ return _privatevariable } }
while other case useful shorten code when don't need setter.
Comments
Post a Comment