开发者

Xcode change global variable for each target

I have a series of target开发者_JAVA技巧s, 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!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜