Xcode/IOS具有相同代码库/项目的多个应用程序 [英] Xcode / IOS multiple apps with same code base / project

查看:57
本文介绍了Xcode/IOS具有相同代码库/项目的多个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置xcode,以允许我使用相同的代码但具有不同的应用程序图标,资产和不同的数据库来构建/发布2个应用程序.

I'm trying to set-up xcode to allow me to build / publish 2 apps using the same code but with different app icons, assets and a different database.

如果我有2个使用相同代码的应用程序:

if I have 2 apps using the same code:

  • app 1:水果列表(显示水果列表)
  • 应用2:素食列表(显示素食列表)

对于这两个应用程序,我将具有唯一的捆绑软件ID(当然),相同的代码,但具有不同的图像和数据库.如何设置Xcode来拥有1个项目并能够选择我要构建的应用程序?

For both apps I would have a unique bundle ID (of course), same code, but different images and database. How can I set-up Xcode to have 1 project and be able to select what app I want to build?

我似乎理解我们可以选择使用方案,目标或构建配置,但是到目前为止,我发现比其他任何东西都更加令人困惑.

I seem to understand we have the option to use schemes, targets or build configuration but so far what I found was more confusing than anything else.

任何对此的建议/帮助都将受到欢迎!在这种情况下,我有一个疯狂的解决方案,那就是要有多个项目,并将更改从一个复制到另一个.

Any suggestion / help on this would be welcome! I sound like a mad solution to have multiple projects in this case and duplicating changes from one to the others.

谢谢.

推荐答案

选项1 :

最简单的方法是拥有一个项目并添加多个"app"应用程序.目标.您需要确保每个目标都添加了正确的源文件(有关如何执行此操作的大量信息,包括:

The simplest way is to have one project and add multiple "app" targets to it. You'd need to make sure that each target had the correct source files added to it (plenty of info on SO about how to do this including: Xcode easily add multiple files to a target).

您提到的每个目标都可以有一个单独的分发包ID,但是您可以选择要添加到每个源文件/映像/等中的文件.您还可以在构建设置"窗口中设置单独的构建标志,环境变量等.每个目标.

Each target could have an individual bundle ID as you mention, but you could choose which source files/images/etc to add to each one. You could also set up separate build flags, environment variables, etc in the "Build Settings" for each target.

您将使用Xcode工具栏(源文件选项卡上方)中的目标菜单来选择要构建和运行的目标.

You'd use the target menu in the toolbar of Xcode (above the source file tabs) to select which target you want to build and run.

选项2 :

另一个选项(或者实际上是选项1的变体)是在同一项目中具有2个应用程序目标(与选项1相同),并且还制定了第三个目标,这将是一个框架.该框架可以封装应用之间的一些共享代码.例如,在我的一个应用程序中,我有一个音频引擎,该音频引擎在该应用程序的iOS和macOS版本之间共享.该框架的源文件仅属于一个目标(框架),然后将该框架添加为两个应用程序目标的依赖项.

Another option (or really, a variation on option 1) is to have 2 app targets in the same project (same as option 1) and also make a 3rd target, which would be a framework. That framework could encapsulate some of the shared code between the apps. For example, in an app of mine, I have an audio engine that is shared between the iOS and macOS versions of the app. The source files to that framework only belong to one target (the framework) and then the framework is added as a dependency of both app targets.

这篇关于Xcode/IOS具有相同代码库/项目的多个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆