By reading this post, It looks like certain rules should be considered when declaring global variables.
So I tried declaring global variables in the .m file. However, the code sense seems not happy to do this for me. For example, say I already have 2 lines in the .m file:
@implementation ViewController
@synthesize abc, xyz;
Now I want to add “BOOL isChecked;”.
If I type this below “@synthesize” (or just between @implementation and @synthesize), the code sense actually suggests me to input “bool” (lower case) as I am typing “BOOL”. If I type “BOOL” above “@implementation”, it would suggest “BOOL” successfully.
Surely, the global variable is part of this class which means it should be inside the implementation. I am not sure why it doesn’t like to let us do this.
This makes me feel that Objective-C doesn’t like us to declare global variables below @synthesize. But my question is WHY? What I feel is that there may be a reason or Apple made a bug here.
Global variables aren’t part of a class. Sure, you can put them inside an
@implementationblock, but they’re really not a part of the class — they’re global — so they don’t really belong there.Objective-C doesn’t have class variables like Java or other languages do. You can fake them with global variables and class methods that access those variables, but at the end of the day, they’re global, not specific to a class.