Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a target to an Xcode project

I have an iPhone application which is currently in the app store. I want to make what is effectively exactly the same application, but which is free of charge and features ads.

My plan was to effectively just copy the project, create a new one and add ads into the code and release as separate app. However, someone mentioned that the best solution would be to add an additional target to the existing application, providing two binaries at run time.

Seems like a good solution to me, however I am a little confused as to how I would go about altering the code to have ads built into the new target, and leaving the original untouched?

like image 808
Paul Morris Avatar asked Sep 13 '11 22:09

Paul Morris


People also ask

What does add to targets mean in Xcode?

"Add to target" means that the file has to be in the "Compile Sources" group of your LogicTests-target. You can also check if a file has been added to the currently active target by looking at the right Checkbox in the "Detail" panel: Copy link CC BY-SA 2.5.

How do I change my target in Xcode?

Select the project from the project navigator to open the project editor and see a list of the app's targets. To rename a target, select it, press the Return key, and enter the new name. If all you want to do is rename the app, you're finished.


2 Answers

I followed this tutorial which, although old, was basically the same for xcode 4. I duplicated the target and p-list, making sure I was able to run it with changes and not affect the full version target.

I then duplicated the .xib files that would be different. If you look under the project settings, somewhere you can find a list which allows you to choose which resources are included. Include the lite version's xibs in the the lite version, and the full version's in the full respectively. Then you will be able to edit each without affecting the other.

The icons and images can be changed in the same way. Simply create a lite version icon set or other set of images and include the lite icons in the lite target's resource settings instead of the full version's images.

Also, you'll want to create some preprocessor macros. In the build tab look for them, and crete a macro called LITE_VERSION (or whatever you want, it doesn't really matter) for every preprocessing option - debug, distribution and release.

That allows you to add differing code in the same .h and .m files. Simply use

#ifdef LITE_VERSION
// Lite version only code here
#endif

to separate the two. You can also use #ifndef LITE_VERSION to add code only to the full version.

That's it! After all of the above steps, you should be able to edit the lite version's .xib files, put code into the lite or full version only, and have separate images and icons for each.

like image 130
Daniel G. Wilson Avatar answered Sep 28 '22 11:09

Daniel G. Wilson


XenElement's answer is correct. But you should see the best practice to do it. You should have an identifier class to check for targets. If you use macros everywhere in the code, it won't seem good for you and other developers as well. In this little blog post you can see how to create that kind of an identifier class and learn some best practices about targets in xcode.

like image 29
rordulu Avatar answered Sep 28 '22 12:09

rordulu