8

Hopefully this is a simple question to answer - I think I'm being a n00b here.

I have, for the first time, created an XCode project with two targets. But I now want to add some code to differentiate between my two targets.

#ifdef MyTargetOne
    x = 1;

#ifdef MyTargetTwo
   x = 2;

I have two targets, but where do I declare "MyTarget1" and "MyTarget2"??

THANKS GUYS!

theDuncs
  • 4,649
  • 4
  • 39
  • 63
  • 2
    And note that, as a general convention, defined names should be, eg, "MY_TARGET_1" and "MY_TARGET_2". (It's a rule that can be broken for good reason on occasion, but this isn't one of them.) – Hot Licks Nov 25 '11 at 13:33

1 Answers1

12

For each target you need a target-specific define - you can use the Preprocessor Macros setting for this ([GCC_PREPROCESSOR_DEFINITIONS, -D]) - add MyTargetOne=1 in the first target and MyTargetTwo=1 in the second.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • scuse me, but i don't find Preprocessor Macros in Build Settings of each Target. I find it only in Project's Build Setting – Jayyrus Jan 13 '12 at 08:59
  • @JackTurky: the exact locations for the target settings depend on what version of Xcode you are using (Xcode 3 and Xcode 4 are very different in this respect) - if you can't find it then post a new question stating what version of Xcode you are using – Paul R Jan 13 '12 at 09:05
  • done! http://stackoverflow.com/questions/8848263/how-to-differentiate-multiple-targets-on-xcode-4-2 – Jayyrus Jan 13 '12 at 09:20