I am trying to create a class with static const variables that can be used from outside the class, but I cannot figure out how to initialize this variable.
Example Code:
@interface ExampleClass
{
static const int CONST_VAR;
}
- (id) init;
@end
@implementation ExampleClass
- (id) init {
CONST_VAR = 1;
}
@end
I want to be able to reference the static constant variable like this:
ExampleClass.CONST_VAR;
You should assign a value to this static variable by doing the following:
Because this is a static variable or “class variable”, you must use the class name in any case regardless of where you are this includes from inside the same class.
Hope this helps.