class - Difference between a property and a global variable [objective c] -
i'm wondering difference between class's public global variable , class's property (objective-c ios programming). thing notice have use pointer notation -> access class's global variable rather dot.
i've read changing code using globals using properties can program breaking change. true , if so, why?
thanks!
edit:
block.h
public global variable (i think?) [edit: understand instance variable, thanks]
@interface block : gameobject { @public int type; skemitternode *particles;}
property
@property (nonatomic) cgfloat x;
no, not "global variable".
it called instance variable.
a property (but not necessarily) has associated instance variable, modern compilers hide you.
the big difference between using instance variable is, property accessed through accessors (in case setx:(cgfloat)x?
and -(cgfloat)x`.
if wanted, overwrite these accessors , special handling, say, whenever variable accessed.
it possible bypass accessors using instance variable directly. in case of auto-synthesized ivar, _x
.
note ->
not necessary in either case
Comments
Post a Comment