43

Probably this is pretty simple, but I can't find a way to define a preprocessor macro for a target in Xcode 6.

Shyam Bhimani
  • 1,310
  • 1
  • 22
  • 37
user1051307
  • 483
  • 1
  • 5
  • 13
  • Related: "[How to define a preprocessor symbol in Xcode](https://stackoverflow.com/q/367368/90527)" – outis Jun 11 '19 at 21:11

2 Answers2

103

I've done a screenshot to show where it is in Xcode, because it's easier :)

enter image description here

  1. Select project file
  2. Select the target you want
  3. Go to Build Settings
  4. Search for 'preprocessor'
  5. Add your preprocessor macro either for Debug, Release, or both.
JoeFryer
  • 2,751
  • 1
  • 18
  • 23
  • 3
    Thank you JoeFryer!!! ...you saved my day! I couldn't find it because I had the 'Basic' tab selected! ...stupid mistake of mine! – user1051307 Nov 14 '14 at 11:57
  • @user1051307 don't forget to mark the answer as correct (if it is correct) – JoeFryer Nov 14 '14 at 15:44
  • 4
    And if you happen to search your (insert important bodypart here) off for this setting make sure, the filter is set to `ALL` settings, not just `BASIC`... – thst Jul 20 '15 at 16:04
  • If I want for both debug and release I enter it twice? No place to put shared ones? When looking at the situation before I edited, I saw $(inheritedxxx) -- can't remember the exact spelling. Seemed like there was some support for something a bit better than having to repeat myself. But couldn't figure it out. – John M Jul 27 '15 at 16:55
  • `$(inherited)` means that the settings are inherited from the project level to the target level. This probably isn't what you want, so yes, in your case, you could add it twice. – JoeFryer Jul 28 '15 at 08:37
  • @JohnM, if you enter a value on a line *without* expanding it, the value is applied to all underlying options, i.e. debug and release. If you want the value to apply to one option, expand the option list and set the individual values. – Elise van Looij Jan 07 '16 at 11:22
  • 1
    For a related swift migration use the following: https://stackoverflow.com/questions/38813906/swift-how-to-use-preprocessor-flags-like-if-debug-to-implement-api-keys/47395485 – Nick N Jan 12 '20 at 03:43
5

In Xcode 9 you have to add a preprocessor macros to Project, not Target. Also don't forget to add "D" as the firs letter. For example, "DDebug", then it works.

Irina
  • 177
  • 2
  • 4