Class global variables in Objective-C -
i'm trying create variables can accessed class coming java background i'm struggling understand in objective-c..
in java have:
public static int main_menu = 1, selection_screen = 2;
these can accessed anywhere so:
classname.main_menu;
how achieve same thing in simplest form objective-c keeping within class?
in objective-c, classes have no static members. best can imagine creating getter , setter class method utterly ugly global variable:
static t _member = initialvalue; + (t)somestaticmember { return _member; } + (void)setsomestaticmember:(t)newval { _member = newval; }
if need getter, i. e. emulation of read-only member, move static variable inside function, @ least have 1 less global way.
but: if need integer constants, why not use enum
? or @ least macros?
Comments
Post a Comment