如何在 Xcode 4 中定义预处理器宏?
我为我的应用程序设置了两个目标(精简版和专业版),并且我想在每个目标的代码中集成一些细微的差异(例如,专业版不会显示任何 iAd 横幅)。
我环顾四周,发现最简单的方法是使用预处理器宏。我面临的问题是如何在 Xcode 4 中设置它们。我想在一个目标和目标中设置一个名为“PRO_VERSION”的宏。另一个是“LITE_VERSION”。
下面是我打算如何使用它们的示例:
#ifdef PRO_VERSION
// Hide ad banners
#else
// Show ad banners
#endif
I have two targets set up for my app (a lite version and a pro version) and I want to integrate some subtle differences in the code for each of them (e.g. the pro version will not show any iAd banners).
I have been looking around and I see the easiest way to do this is through the use of preprocessor macros. The issue I'm facing is how to set them up in Xcode 4. I want to set up a macro called 'PRO_VERSION' in one target & 'LITE_VERSION' in the other.
Below is an example of how I intend to use them:
#ifdef PRO_VERSION
// Hide ad banners
#else
// Show ad banners
#endif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要更改的构建设置称为“预处理器宏”,可以在“项目设置”窗格的“构建设置”选项卡中找到(使用搜索框找到它)。在“项目设置”窗格的左侧依次选择每个目标,然后修改“预处理器宏”设置。
该设置被指定为以空格分隔的预处理器宏列表,格式为“foo”或“foo=bar”。
The build setting you need to change is called 'Preprocessor Macros' and it can be found in the 'Build Settings' tab of the Project Settings pane (use the search box to find it). Select each target in turn in the left-hand side of the Project Settings pane then modify the Preprocessor Macros setting.
The setting is specified as a space-separated list of preprocessor macros in the form 'foo' or 'foo=bar'.
我现在不在我的 Mac 上,所以我无法给出完整的分步说明,但我相信这应该是准确的,即使不像我那样详细。创建一个新的构建目标。转至此新目标的配置屏幕。编译选项旁边应该有一个选项卡。在此选项卡中应该有一行用于其他编译器标志。在其中输入
-DPRO_VERSION
。I'm not on my mac at the moment, so I can't give full step-by-step directions, but I believe this should be accurate, if not as detailed as I would otherwise be. Create a new build target. Go to the configuration screen for this new target. There should be a tab along the lines of compilation options. In this tab there should be a row for other compiler flags. In there, put
-DPRO_VERSION
.