views:

70

answers:

2

Hi there,

I have a series of targets, and each one looks at a global variable I am currently storing in a constants file for the name of the directory in which that app's resources live. However, this means that I have to change this value each time i change the target, which is a terrible process.

What is the best way to change that value in each target? Or should i specify this value somewhere in my target plist ? If so how do i retrieve that value?

Thanks!

A: 

Go to your target properties by double clicking the target and find Preprocessor Macros. Add a constant, such as FILE_PATH="/some/place/green/" and then when you want to use it, just

fopen(FILE_PATH... or whatever function/method you want to perform on FILE_PATH

do the definition part for each target.

Matt Williamson
+2  A: 

With your project open in Xcode, look in the Groups & Files panel for your Target. Right click to bring up your popup menu. Select Get Info. Select the build tab. Scroll down to the "Preprocessor Macros" and add something like "MY_OPTION_1". Do something similar for your other targets. Say "MY_OPTION_2", "MY_OPTION_3", etc.

Now, in your code you can do a define test. Like

#ifdef MY_OPTION_1
   // define values here
#endif

#ifdef MY_OPTION_2
   // define values here
#endif

#ifdef MY_OPTION_3
   // define values here
#endif

Then, depending on what target you use, the values within the corresponding defines are used.

No one in particular