iosxcodexcode-schemexcode-build-settingsxcode-target

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:

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.


Solution

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