swift - Need clarification regarding computed properties -


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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -