Possible Duplicate:
Global Variables in Cocoa/Objective-C?
problem with declare a global variable in objective c
I was defining a global variable inside my .h, which other classes were accessing by including the classes “.h” file. This worked fine, from advice I received, I’ve now moved the variable to the “.m”, because I was informed, that otherwise every class that includes the .h will be redeclaring it, is this correct? But now my other files can’t access it, and I’m assuming I’m not supposed to include “.m” files…. should I use the #define preprocessor, so that is only defined once? How do i do this?
You can declare variables in
.hfiles.globals.h:
You cannot define the variable in a
.h, You have to define it in a.cor.m:globals.m:
You can import
globals.hfrom any other file that needs to accessmyGlob:myApp.m: