enums - Enumerated type as a static variable in Objective-C -


i need static variable holds enumerated type accessed , changed other classes. can access value, when try change it, new value not stored. class it's declared in not instantiated.

this enum declaration:

typedef ns_enum(nsinteger, weapontype) {     single, dual }; 

i have static getter , setter declared in .h file:

+(weapontype)shipweapontype; +(void)setshipweapontype:(int)atype; 

in .m file have static variable

static weapontype shipweapontype; 

and getter , setter implemented follows:

+ (weapontype)shipweapontype {     return shipweapontype; } + (void)setshipweapontype:(int)atype {     shipweapontype = atype; } 

shipweapontype returns 0. have tried having setshipweapontype require actual enum type rather int, makes no difference.

any appreciated!

i suspect you're missing obvious, have appears though should work. did test in single class inside default sprite kit project since had open, , worked. here's looks like:

//=======  .h ========== typedef ns_enum(int, testenumtype){     nulltype,     onetype,     twotype,     inittype,  };  @interface myscene : skscene  +(void)setstaticvar:(int)var; +(testenumtype)getstaticvar;  //========= .m ============== static testenumtype thestaticvar = inittype;  @implementation myscene  +(void)setstaticvar:(int)var {     thestaticvar = var; }  +(testenumtype)getstaticvar {     return thestaticvar; }  -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     [myscene setstaticvar:onetype];     nslog(@"the var: %i", [myscene getstaticvar]); //result var: 1  } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -