如何使用 Xcode 4.2 区分多个目标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8848263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:59:07  来源:igfitidea点击:

How to differentiate multiple targets with Xcode 4.2

xcodexcode4xcode4.2targetbuild-settings

提问by HymanTurky

I've developed a lite version of an app. Now I want to create a paid version. So I've duplicated the target, changed its name (so change plist and other stuff with that name) and now I have to differentiate in code. I'm using Xcode 4.2 and I see on the web that I have to create a preprocessor flag. My problem is that this flag in Xcode 4.2 is only in the project's build setting and not in the target's build setting.

我开发了一个应用程序的精简版。现在我想创建一个付费版本。所以我复制了目标,更改了它的名称(因此更改 plist 和其他具有该名称的内容),现在我必须区分代码。我正在使用 Xcode 4.2,我在网上看到我必须创建一个预处理器标志。我的问题是 Xcode 4.2 中的这个标志仅在项目的构建设置中,而不在目标的构建设置中。

I will need to be able to do something like this:

我需要能够做这样的事情:

#ifdef paid
    ...
#else
    ...
#endif

回答by Tomasz Wojtkowiak

Use preprocessor macros to do this. Go to Target -> Build Setting and choose "All configurations" (this is very important). Next find field "Preprocessor Macros".

使用预处理器宏来做到这一点。转到目标 -> 构建设置并选择“所有配置”(这非常重要)。接下来找到字段“预处理器宏”。

In this field, add the flag in ex. PAID_VERSION. Now you can use this flag in code:

在此字段中,在 ex 中添加标志。PAID_VERSION。现在你可以在代码中使用这个标志:

#ifdef PAID_VERSION
    NSLog(@"Paid version");
#else
    NSLog(@"Lite version");
#endif