Is there such thing as 'didGet' in Swift? A method that is run whenever a variable is accessed? -


basically, want this:

var counter : int = 0; private var _data : string; var data : string {     { counter += 1; return _data; }     set { _data = newvalue; } } 

then want reduce this:

var counter : int = 0; var data : string {     { counter += 1; return data; }     set { data = newvalue; } } 

but noticed can't done. (error: variable used within initial value). want simplify this:

var counter : int = 0; var data : string {     didget { counter += 1; } } 

but there's no such thing didget. there way without adding new other variable? need run counter += 1 every time data accessed, without adding new variable storage. thanks.

no, there no way without adding new variable.

if return in get method of variable same variable, create infinite loop.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -