Is there a compile time variable that lets me detect whether the current build is for debug or release? If not, how can I define my own?
-
Duplicate : https://stackoverflow.com/questions/9063100/xcode-ios-how-to-determine-whether-code-is-running-in-debug-release-build – Samuel Peter Feb 17 '15 at 14:30
1 Answers
As of Xcode 4, the Build, Run, Test, and Analyze actions produce Debug builds by default; the Profile and Archive actions produce Release builds. This is controlled by editing the scheme, selecting the action, then changing the build configuration under the Info tab. To Apple in Xcode 4, the Archive action is the final "build this for release so I can distribute it" action. This is the highest level at which you manage these settings.
At the lower level, your target contains its build settings, which define configurations. By default, there are two configurations: Debug and Release. You can find (and manage) them by selecting the project (the root node) in the Project navigator, then choosing the Info tab. They're found under the Configurations group.
To edit the settings for the various configurations for a given target, choose the target in the Targets list, then choose the Build Settings tab. The grid looks (and sort of is) complicated and you should read the docs for details (esp. the what the different columns represent). To answer your question, each setting can be edited to change the setting for all configurations or expanded with the disclosure triangle so you can specify configuration-dependent settings. For example: under Release configuration, you might want to strip debugging symbols; under Debug, you do not.

- 60,946
- 14
- 140
- 135
-
*Shameless plug I hope is okay without a hyperlink: Chapter 14 of my book, Mastering Xcode 4, spends nearly 40 pages explaining this very topic.* :-) – Joshua Nozzi Aug 22 '11 at 12:38
-
-
What are you trying to do? If you only want to know what build *configuration* is being used, then you only need to know what action you just chose (did you say Build? Run? Profile? Archive?) and the current scheme's settings for that action. If you tell it to Run, a scheme's default configuration for the Run action is "Debug", so Xcode will build with the Debug configuration. – Joshua Nozzi Aug 23 '11 at 12:11
-
I'm looking to branch code based on a variable defined at compile time. – Morrowless Aug 24 '11 at 05:35
-
Ah. That's some additional detail you might've put in your question. :-) Here's another SO question that describes this: http://stackoverflow.com/questions/5272296/how-to-add-preprocessor-define-globally-for-debug-configuration-in-xcode-4 – Joshua Nozzi Aug 24 '11 at 12:29