Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

if I have 2 apps using the same code:

  • app 1: fruit list (display a list of fruits)
  • app 2: Veggie list (display a list of Veggie)

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.

Thank you.

like image 853
Slamit Avatar asked Jan 24 '26 05:01

Slamit


2 Answers

Option 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).

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.

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.

Option 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. 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.

like image 68
jnpdx Avatar answered Jan 25 '26 17:01

jnpdx


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.

enter image description here

To share code between apps, just add a file to both app targets.

enter image description here

like image 38
matt Avatar answered Jan 25 '26 17:01

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!