Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a global #define in XCode

Tags:

xcode

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

like image 246
n179911 Avatar asked Jul 03 '09 16:07

n179911


People also ask

What does global mean in Python?

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.

What does global mean in programming?

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.

How do you display global variables?

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.

How do you make a global function in Python?

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.


2 Answers

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.

like image 86
e.James Avatar answered Sep 28 '22 07:09

e.James


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.

like image 40
Robert Avatar answered Sep 28 '22 07:09

Robert