Tutorial – Same Xcode Project Create Multiple Products for iPhone

Some times you need to build two versions of your iPhone application(i.e lite and full version) from the same Xcode project. So one way is to make two copies of your Xcode project and manage both independently which is not a good way. Because when you have to change a little in your iPhone application, you have to change in both copies of your Xcode projects. So its not easily manageable for anyone to change a line of code in both codes of one application. So following this tutorial, you can make different applications from one source Xcode project!

Xcode is really a good IDE which provide lot of features. Everyday I come across to know more about Xcode features while building iPhone applications. So today I am going to share another most important feature of Xcode which helps you when you are thinking to create two iPhone application but with same project. So theme of this tutorial is to, create one application in Xcode and generator two builds(binary) form same code. In other words, you don’t have to manage two copies of your application. Just create one application and generator two copies of build(binary) files for apple store.

So let just start without going any further discussion. What I will do in this tutorial, create a project in Xcode and place three buttons on controller view. One button will display for lite version and two button will display on full version.

So lets start:

1. Create a “View-Based Application” project in Xcode and named it “HelloWorld” (figure 1figure 2).
Picture%201 Tutorial   Same Xcode Project Create Multiple Products for iPhonePicture%202 Tutorial   Same Xcode Project Create Multiple Products for iPhone

2. In your HelloWorldViewController.h file write the following code for linking with Interface builder (figure 3):

IBOutlet UIButton *buttonOne;
IBOutlet UIButton *buttonTwo;
IBOutlet UIButton *buttonThree;

Picture%203 Tutorial   Same Xcode Project Create Multiple Products for iPhone

3. Open HellowWorldViewController.xib file in interface builder and place three buttons on the view (figure 4). Now select three buttons and set there hidden property to true.

Picture%204 Tutorial   Same Xcode Project Create Multiple Products for iPhone

4. Now map those buttons with HelloWorldViewController class (figure 5).

Picture%205 Tutorial   Same Xcode Project Create Multiple Products for iPhone

5. Open HelloWorldViewController.m file and write down following code in viewDidLoad method ( I will explain this code later): (figure 6)

#ifdef LITEVERSION
buttonOne.hidden = NO;
#endif
#ifdef FULLVERSION
buttonTwo.hidden = NO;
buttonThree.hidden = NO;
#endif

Picture%206 Tutorial   Same Xcode Project Create Multiple Products for iPhone

6. Everything is setup for your code. Lets change few Xcode settings to make two binary(build) for our application. Expand Target from your “Group & File” side bar and right click on “HelloWorld”, select “Duplicate”.(figure 7)

Picture%207 Tutorial   Same Xcode Project Create Multiple Products for iPhone

7. Rename the duplicate file(HelloWorld copy) to HelloWorldLite (figure 8).

Picture%208 Tutorial   Same Xcode Project Create Multiple Products for iPhone

8. Now you will see “Info.plist” and “Info copy.plist” in your Resources folder (figure 9). Rename “Info copy.plist” to “InfoLite.plist” (figure 10). To check if everything goes right, select “HelloWorldLife” application from target and clicked on “info”(or right click on it and select ‘get info’ –figure 11) from Xcode. Please check that in configuration combobox “All configration” is selected and in show combobox “All settings” are selected. In search field type ‘info.plist file’ and it will show you the “InfoLite.plist” in value column (figure 12). (Do not close info window)

Picture%209 Tutorial   Same Xcode Project Create Multiple Products for iPhonePicture%2010 Tutorial   Same Xcode Project Create Multiple Products for iPhonePicture%2011 Tutorial   Same Xcode Project Create Multiple Products for iPhonePicture%2012 Tutorial   Same Xcode Project Create Multiple Products for iPhone

9. Now if you are in info screen, please type “product name” and change the value from “HelloWorld” to “HelloWorldLite” (figure 13).

Picture%2013 Tutorial   Same Xcode Project Create Multiple Products for iPhone

10. Last step, Still info window is open. Clicked on bottom left of info screen “Add and edit build setting” (figure 14) and type “OTHER_CFLAGS” in “Setting” column and type -DLITEVERSION in value column (figure 15). Close info window.

Picture%2014 Tutorial   Same Xcode Project Create Multiple Products for iPhonePicture%2015 Tutorial   Same Xcode Project Create Multiple Products for iPhone

11. Now select “HelloWorld” form target (figure 16) and right clicked on it to select “Get Info” (figure 17). Now bottom of this window, select “add and edit build setting” (figure 14) and type “OTHER_CFLAGS” in “Setting” column and type -DFULLVERSION in value column (figure 15).

Picture%2016 Tutorial   Same Xcode Project Create Multiple Products for iPhonePicture%2017 Tutorial   Same Xcode Project Create Multiple Products for iPhone

Now its time to build full version for helloworld, select the build properties (figure 18) “Simulator – iphone os 2.0″ in Active SDK and in Active Configuration select “Debug” and in Active Target select “HelloWorld” (figure 18). Now clicked on build and go. See the result (figure 19)

Picture%2018 Tutorial   Same Xcode Project Create Multiple Products for iPhonePicture%2019 Tutorial   Same Xcode Project Create Multiple Products for iPhone

Now to build for lite version of the helloworld, select the build properties (figure 20) “Simulator – iphone os 2.0″ in Active SDK and in Active Configuration select “Debug” and in Active Target select “HelloWorldLite” (figure 20). Now clicked on build and go. See the result (figure 21)

Picture%2020 Tutorial   Same Xcode Project Create Multiple Products for iPhonePicture%2021 Tutorial   Same Xcode Project Create Multiple Products for iPhone

Final result will look like this (figure 22)

Picture%2022 Tutorial   Same Xcode Project Create Multiple Products for iPhone

[update 21 April] You can download this code from here. (Thanks Ajay for reminding me icon smile Tutorial   Same Xcode Project Create Multiple Products for iPhone )

Popularity: 10% [?]

My name is Adeem M Basraa. I am a software engineer from Lahore, PK. I’ve been involved in software development for nearly 4 years, with the last 1 year focused on application development for mobile devices (iPhone & Android).

16 Comments on "Tutorial – Same Xcode Project Create Multiple Products for iPhone"

  1. Aamir ALi says:

    Nice tutorial to manage the multiple builds of single project.
    :)

  2. gaith says:

    great…. very helpful post… been wondering about this feature for some time. i am actually using it to show my client two different design options of the same app

  3. Ajay says:

    Nice tutorial, would be be possible to upload / email-me the source code? It would be easier to play with it.

    Thanks

    Ajay

  4. admin says:

    @gaith
    Thanks for liking :)

  5. admin says:

    @Ajay
    thanks for reminding me. Please find the code link in this post.

  6. todd says:

    Instead of OTHER C FLAGS we usually use “Preprocessor Macros” (GCC_PREPROCESSOR_DEFINITIONS), but I don’t know that it’s any better.

  7. Michael Kaye says:

    Question – how do I handle things like Localizable.strings and InfoPlist.strings. You can’t have two copies of these files and there is no info.plist setting I can use to target the correct file with a different name. Plus how would one handle different Default.png for each target?

  8. admin says:

    @Michael,
    Please check my latest post and grab the code. I hope this helps you.

  9. Frack says:

    Very good tutorial, but the images won’t show up!

  10. nura says:

    first let me appreciate you for this great tutorial.
    Out of scope,I need to know how we can create a group dynamically(runtime) in to the same project.

    thanks in advance..

  11. Jason says:

    If I have a tab bar controller, how can I hide one of the tab bar items for lite version?

  12. beto says:

    Reupload the images and code please

Trackbacks for this post

  1. Tutorial Part 2: same xcode project create multiple products for iphone using Script | iPhone Diary
  2. [iPhone] Tutorial – 하나의 Xcode Project로 여러 버전의 Product 만들기 – Tutorial – Same Xcode Project Create Multiple Products for iPhone | Alones world
  3. Hidden Xcode build, debug and template settings | Advanced App Development
  4. Mac, iPhone, iPad » iPhoneアプリの無料版と有料版を同じソースから作りたい

Got something to say? Go for it!