If you declare a static variable in the implementation file of a class, then that variable is only visible to that class.
You could declare the static variable in the header file of the class, however, it will be visible to all classes that #import
the header.
One workaround would be to declare the static variable in the parent class, as you have described, but also create a class method to access the variable:
@implementation ServerParser
static NSString *currentElement;
...
+ (NSString*)currentElement
{
return currentElement;
}
...
@end
Then, you can retrieve the value of the static variable by calling:
[ServerParser currentElement];
Yet the variable won't be visible to other classes unless they use that method.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…