In Java, the following code is fine, no error.
class ConstantA{
public static String MY_TEST = "My Test";
}
import ConstantA;
Class TestClass{
public void test(){
System.out.println(ConstantA.MY_TEST); // it's work fine.
}
}
According to above java concept, it doesn’t work on Objective-C,
in ConstantA.h file
extern NSString * const MY_TEST;
@interface ConstantA : NSObject
@end
in ConstantA.m file
NSString * const MY_TEST = @"My Test";
@implementation ConstantA
@end
in main.m file ( error occurs here)
#import "ConstantA.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
NSLog(@"%@",ConstantA.MY_TEST); // error: Property 'MY_TEST' not found on object of type 'ConstantA'
}
}
Can help me to solve this problem?
thanks so much
Use directly the global variable, without class name:
MY_TEST and NOT ConstantA.MY_TEST.