Objective C - Static and global variable?

前端 未结 2 513
清歌不尽
清歌不尽 2021-01-12 02:01

In my .m file for a class named Ad , I have 3 static strings

static NSString *AdStateDisabled = @\"disable\";
static NSString *AdStateExpired = @\"expired\";         


        
2条回答
  •  耶瑟儿~
    2021-01-12 02:32

    First, remove the static. Static variables and functions in C and Objective-C mean that they're visible only to the current compilation unit (that is more or less: only the file that you've declared the statix variable in can see it).

    Next, you also need to declare the variables in a public header file with "extern", like the one of the class associated with the class:

    extern NSString *AdStateDisabled;
    

    You can then use them in other files as well, but you would not access them as "Ad.AdStateDisabled" but just as "AdStateDisabled".

提交回复
热议问题