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.
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’.
Next, rename your newly created target.
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.
Now move the file to the folder titled ‘Support Files’.
Go into ‘General’ tab of the new target and click on ‘Choose Info.plist File…’ and select the PList file you just renamed.
Next, go to the Build Settings tab and locate the ‘Packaging’ section, as shown below.
Enter a ‘Product Name’. In the below example, it is the same as the Target name.
Next, go to ‘Wrapper Extension’. Whatever you enter here will become the name of the IPA file you will create using this target.
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:
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).
Here’s the code snippet I wrote inside the AppDelegate.m:
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
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
Whether it’s a brand refresh, public relations push, new website or end-to-end
behaviour change campaign — we’re interested and ready to talk solutions.