简体   繁体   English

Xcode / IOS 具有相同代码库/项目的多个应用程序

[英]Xcode / IOS multiple apps with same code base / project

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.我正在尝试设置 xcode 以允许我使用相同的代码构建/发布 2 个应用程序,但具有不同的应用程序图标、资产和不同的数据库。

if I have 2 apps using the same code:如果我有 2 个应用程序使用相同的代码:

  • app 1: fruit list (display a list of fruits) app 1:水果列表(显示水果列表)
  • app 2: Veggie list (display a list of Veggie)应用 2:Veggie 列表(显示 Veggie 列表)

For both apps I would have a unique bundle ID (of course), same code, but different images and database.对于这两个应用程序,我将有一个唯一的捆绑 ID(当然)、相同的代码,但不同的图像和数据库。 How can I set-up Xcode to have 1 project and be able to select what app I want to build?如何设置 Xcode 以拥有 1 个项目并能够 select 我要构建什么应用程序?

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.在这种情况下,拥有多个项目并将更改从一个复制到另一个,这听起来像是一个疯狂的解决方案。

Thank you.谢谢你。

Option 1 :选项 1

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 ).您需要确保每个目标都添加了正确的源文件(关于如何执行此操作的大量信息,包括: Xcode 轻松将多个文件添加到目标)。

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.正如您所提到的,每个目标都可以有一个单独的包 ID,但是您可以选择将哪些源文件/图像/等添加到每个目标中。 You could also set up separate build flags, environment variables, etc in the "Build Settings" for each target.您还可以在“构建设置”中为每个目标设置单独的构建标志、环境变量等。

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.您可以使用 Xcode 工具栏中的目标菜单(源文件选项卡上方)到 select 您要构建和运行的目标。

Option 2 :选项 2

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.另一个选项(或者实际上是选项 1 的变体)是在同一个项目中拥有 2 个应用程序目标(与选项 1 相同)并创建第三个目标,这将是一个框架。 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.例如,在我的一个应用程序中,我有一个在 iOS 和 macOS 版本的应用程序之间共享的音频引擎。 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.该框架的源文件仅属于一个目标(框架),然后将框架添加为两个应用程序目标的依赖项。

You are describing a project with two app targets.您正在描述一个具有两个应用程序目标的项目。 When you build / run, just switch the scheme popup at the top of the window to the one you want.当您构建/运行时,只需将 window 顶部的方案弹出窗口切换到您想要的那个。

在此处输入图像描述

To share code between apps, just add a file to both app targets.要在应用程序之间共享代码,只需向两个应用程序目标添加一个文件。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM