Create multiple targets iOS app

 Jigar M 
5 min readJul 10, 2015

Building multiple iOS apps from a single project using multiple targets

In this tutorial, you will learn how you can add multiple targets from a single Xcode project so that you do not have to mess with branching or copying useful files or resources to others project. You will always have the current code base with each app and can push out updates to every app for bug fixes or performance improvements with minimal effort. But to do so you will need to understand how to set up multiple build targets, manage assets which are unique to each target (launch images, icons), unique code paths and the application identifier used for code signing and the product name as well.

There are different ways to handle the development of clones. Probably the most common or the one that will first come to mind is using branches.

However, I’m going to tell about the different approach in the form of targets.

Targets VS Branching :

# Using branches is not a bad approach by all means. However, there are some serious drawbacks when using them.
# Firstly, you may need to go back to your first app to solve bugs the users may have found. Once you’ve fixed those bugs, you have to merge those updates to your new branch. By the time you’ve successfully made the merge, you’ll notice that you’ve spend more time here than doing actual work on the new app.
# A Better approach is use Multiple Targets. Most IDE’s have some sort of target support (in Android they are called Flavors).

What is Target?

Apple describes targets as follows:

“A target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace. A target defines a single product; it organizes the inputs into the build system — the source files and instructions for processing those source files — required to build that product. Projects can contain one or more targets, each of which produces one product.”

Each target has its own .plist file that defines values like the bundle identifier, version number and build number which allow you to build unique products within a project. The target also has settings accessible from the project editor in XCode, including Preprocessor Macros found under Build Settings:

Let’s implement in the iOS project. The following steps will help you create multiple targets :

  • To get you started, Create a project or start with an existing project.
    Now, this project have only one target for now. we have to add one other target.
  • Creating a new target is easiest if you duplicate an existing target and make some modifications. This saves a lot of time versus configuring a target from scratch. Start by selecting your project from the navigator:

Now right click your target MultipleTargetDemo, and choose “duplicate” option:

Duplicate the Target

Choose “Duplicate Only” on the popup:

Duplicate Popup and select “Duplicate Only”

This option create the duplicate target and generate MultipleTargetsDemoPro copy-info.plist. Now “Rename” that duplicate target to “MultipleTargetsDemoPro”.

Now, If you look up at the top left part of XCode where you usually choose the device you want to run your app on, you’ll find something called a scheme just to the left of that:

In Below figure[1], this image have the target from where we are running the Xcode app to device or Simulator.

In figure[2], when you are tapping on target, it will open the number of targets if projects have. In figure[2], we just need rename the target name “MultipleTargetsDemo copy” to “MultipleTargetsDemoPro”.

figure [1]
figure [2]

For renaming the target name, we have to Select “Manage Schemes” Option.

select “Manage Schemes”

Click on “MultipleTargetsDemoPro copy”, hit return to make it editable then rename it to “MultipleTargetsDemoPro”. Hit enter once more and then press OK.

Now, All Good.
Remaining part is we need to rename the .plist file. You might have noticed that after you created the new target for the pro version, a new .plist was added to your project. Name is : “MultipleTargetsDemo copy-info.plist”

MultipleTargetsDemoPro copy-info.plist

Rename it to MultipleTargetsDemo copy-info.plist and move it just under the MultipleTargetsDemoPro.plist by dragging it in the navigator.

Change name “MultipleTargetsDemocopy-info.plist” to “MultipleTargetsDemoPro.plist

Now open MultipleTargetsDemoPro.plist. Update the Bundle display name — which is the app’s name to “MultipleTargetsDemo Pro”.

Now only one issue is remaining. When you create any new target or duplicate any target, you must have to assign the .plist file from the Package section.

Select the Build Settings for this MultipleTargetsDemoPro target. In the Packaging section, update Product Name to be “MultipleTargetsDemo Pro”. and Change info.plist name.

Now run the App from top left corner of the Xcode. Select targets simultaneously and check the response.

--

--

 Jigar M 

Technical Lead | iOS | Xamarin | Xamarin.Forms | MAUI | Project Management