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.
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;
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.
4. Now map those buttons with HelloWorldViewController class (figure 5).
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
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)
7. Rename the duplicate file(HelloWorld copy) to HelloWorldLite (figure 8).
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)
9. Now if you are in info screen, please type “product name” and change the value from “HelloWorld” to “HelloWorldLite” (figure 13).
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.
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).
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)
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)
Final result will look like this (figure 22)
[update 21 April] You can download this code from here. (Thanks Ajay for reminding me )
Popularity: 10% [?]