Content options:

Using Multiple Targets in XCode

Posted by: Hamza Azad
5th June 2015


Hi guys, today I’ll show you how to create multiple targets in XCode to create seperate targets in your iOS app. I’ll also go over some interesting use cases of this feature.

As I’m sure you know, XCode allows you to create multiple targets which you can use to build IPA files that all have the same code base, but are customized differently based on their configuration.

So Why Use Multiple Targets in XCode?

The biggest advantage of using multiple targets in XCode, is that you can this feature to make two separate apps using the same code base, but have them branded differently with separate logos and splash screens or even distinct theme colors.

For example, if you have multiple customers and you’re using separate Analytics API keys for each of them. In that case, you can create a separate target for each of them (using the multiple targets feature) and just create a configuration file to define Analytics API separate keys for them.

Here’s how you can create multiple targets in XCode.

Step 1:

First, let’s start by creating a new target in our app (I just created a new sample app)
Right click on the name of your target and click on ‘Duplicate’.

Multiple Targets in XCode

Step 2:

Next, rename your newly created target.

Multiple Targets in XCode

Step 3:

When you do that, you will see a new file has been created in the root folder of your project titled ‘YOUR-PROJECT-NAME-Info.plist’. Rename this file to match the name of the new target.

Multiple Targets in XCode

Step 4:

Now move the file to the folder titled ‘Support Files’.

Multiple Targets in XCode

Step 5:

Go into ‘General’ tab of the new target and click on ‘Choose Info.plist File…’ and select the PList file you just renamed.

Multiple Targets in XCode

Multiple Targets in XCode

Step 6:

Next, go to the Build Settings tab and locate the ‘Packaging’ section, as shown below.

Multiple Targets in XCode

Step 7:

Enter a ‘Product Name’. In the below example, it is the same as the Target name.

Multiple Targets in XCode

Step 8:

Next, go to ‘Wrapper Extension’. Whatever you enter here will become the name of the IPA file you will create using this target.

Multiple Targets in XCode

And that’s it! You now have two separate targets in your project which you can use to create separate IPA files of your app.

Customizing Your Targets:

You can also put target specific information directly in the Info.plist file of the target but I’ll show you a better way to do this.

First, create a new file named ‘Configuration.plist’ and info inside it like this:

Multiple Targets in XCode

As you can see from the screen show above, I added the Analytic API keys that I wanted to use for the two targets inside the Configuration.plist file and now I’ll just write the code to access them inside my AppDelegate.m

But before that, I need to tell my targets where to look for the keys by adding a key-value pair in the Info.plist file of the two targets (as depicted in the screens below).

Multiple Targets in XCode

Multiple Targets in XCode

Here’s the code snippet I wrote inside the AppDelegate.m:

Multiple Targets in XCode

Once you have setup the Configuration.plist file, you can put any information inside it specific to the targets, and on run time you’ll get the required values. By doing it this way, you can keep your code better organized and easy to look up.

Explore our blog

About Folio3

As a leading mobile app development company (iPhone, Android, Windows Phone, HTML5 app development), Folio3 specializes in native app development services and cross platform mobile app development services for the iPhone and iPad. We also offer extensive mobile app testing and QA services. If you have a mobile app idea that you’d like to discuss please or would like to know more about our iPhone app development services, please Contact Us. Learn more about our iPhone, Android and Windows Phone app development services

Comments (0)