properties - property doesn't set after lazy initialization objective-c -


i have bool property , @ start property equals no. want set property yes start of program, opportunity toggle it. this, made getter:

-(bool)turn {     if(!_turn)         _turn = yes;     return _turn; } 

this getter set turn property yes, makes "constant", yes. why?

i thought

if(!_turn) 

construction specially reason want set "not set yet" object value

can answer me why so? , how can set property value want. thanks.

look @ action table:

 turn:     false          true !turn   turn = yes      nothing 

when _turn false, flip true. when _turn true, nothing (there's no else statement). return value of _turn. yea, returning true in cases.

to honest, design not good. if want set initial value of variable value, in init method. provide method toggles value:

-(bool) toggleturn {   _turn = !_turn;   return _turn; } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -