n179911
n179911

Reputation: 20341

Setting a global #define in 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

Upvotes: 12

Views: 13145

Answers (2)

Robert
Robert

Reputation: 38233

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.

Upvotes: 15

James Eichele
James Eichele

Reputation: 119214

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.

Upvotes: 19

Related Questions