14

I'm trying to add a new target to my Xcode project so that I can run the same app, but with subtle difference.

Please can someone guide me through the setup of a new target since it is my first time and I'm not sure how to go about doing it.

In particular, I'm interested how I make the new target run the code in the original app. When I tried creating a new target it just made a new app delegate, and viewController file.

Sorry if this is simple, I'm just quite confused.

EDIT: Please note that I'm after after instructions based in Xcode 4.

2 Answers2

24

In xcode 4, make sure you're in the folder view where you have the project. Select the blue project button, then next to that you can see Targets, Select the target you have there, right click & select duplicate target.

Now you have two build targets.

To apply subtle differences in your app, make a global C flag. in Build settings there is a paragraph named GCC 4.2 - Language, it has a property named Other C Flags. Add your flag here like so:

-DOTHER_VER

Now in your code you can check for this using:

#ifdef OTHER_VER
    // some code.
#else
    // the subtle difference.
#endif
Sietse
  • 7,884
  • 12
  • 51
  • 65
Wolfert
  • 974
  • 6
  • 12
  • thanks for your help. When I duplicate the target it comes up with a 'Target copy', is there a way to rename it throughout the project e.g. 'Target Pro'? –  Oct 21 '11 at 13:33
  • 2
    Yes, under Build Settings there is a property called Product Name. – Wolfert Oct 21 '11 at 13:34
2

After you create your new target from settings of your project, you can create an identifier class to check the target. If you use macros everywhere in your code, it'll not be readable and feasible. You can check this tutorial-blog to learn how to do it, besides you may see some best practices there.

rordulu
  • 412
  • 4
  • 12