xcode 如何添加新的 iPhone 目标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7849633/
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:11:40  来源:igfitidea点击:

How to add new iPhone target

iphonexcodetarget

提问by The Crazy Chimp

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

我正在尝试向我的 Xcode 项目添加一个新目标,以便我可以运行相同的应用程序,但有细微的差别。

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.

特别是,我对如何让新目标在原始应用程序中运行代码很感兴趣。当我尝试创建一个新目标时,它只是创建了一个新的应用程序委托和 viewController 文件。

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

对不起,如果这很简单,我只是很困惑。

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

编辑:请注意,我遵循基于 Xcode 4 的说明。

回答by Wolfert

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.

在 xcode 4 中,确保您位于项目所在的文件夹视图中。选择蓝色的项目按钮,然后在旁边你可以看到Targets,选择你在那里的目标,右键单击并选择duplicate target

Now you have two build targets.

现在您有两个构建目标。

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

要在您的应用程序中应用细微的差异,请创建一个全局 C 标志。在Build settings有一个名为 的段落中GCC 4.2 - Language,它有一个名为 的属性Other C Flags。在此处添加您的标志,如下所示:

-DOTHER_VER

Now in your code you can check for this using:

现在在您的代码中,您可以使用以下方法检查这一点:

#ifdef OTHER_VER
    // some code.
#else
    // the subtle difference.
#endif

回答by rordulu

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-blogto learn how to do it, besides you may see some best practices there.

从项目设置创建新目标后,您可以创建标识符类来检查目标。如果您在代码中随处使用宏,它将不可读和不可行。您可以查看此教程博客以了解如何操作,此外您可能会在那里看到一些最佳实践。