Can you please tell me how can I set a global #define in my Xcode project? I don't want to put #define DEBUG in every .h of my project.
Thank you
In the programming world, a global variable in Python means having a scope throughout the program, i.e., a global variable value is accessible throughout the program unless shadowed. A global variable in Python is often declared as the top of the program.
A global variable is a programming language construct, a variable type that is declared outside any function and is accessible to all functions throughout the program.
Use the SHOW GLOBALS command to display the GLOBALS panel. Press the Show Field key to display the entire entry field. The maximum length for a global variable on the Show Global Variable screen is 32,768 bytes. Type the value for the variable on the lines provided.
The global Keyword Normally, when you create a variable inside a function, that variable is local, and can only be used inside that function. To create a global variable inside a function, you can use the global keyword.
This is generally done in the Xcode project properties. Right-click on the project itself in the project window (the project is the top level of the heirarchy) and choose "get info". This will bring up the project inspector window. In the inspector window, choose the "Build Settings" tab. Now, use the search field to find an entry called "preprocessor macros", and put the string DEBUG
into that entry.
If you do this only for the "Debug" build configuration (there should be a drop-down menu within the project inspector window), then this DEBUG
macro will only be #defined when you are actually debugging.
See Apple's documentation for all the dirty details.
Another option is to use your project's .pch
file. It stand for precompiled header file and it compiled before any other file in your project.
This means if you put a #define
or an #import
in the .pch
file it will be included in every file in your project.
EDIT
As I have recently found out, you have to be carful using the .pch
file.
-- EVERY CHANGE YOU MAKE TO A FILE IN THE .pch
EVERY FILE WILL BE RECOMPILED.--
IF you have a large project this could take some time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With