13

I do not want to maintain two sets of code. I just need to limit some features in the Lite version and add some advertisements on it.

How to do that?

virsir
  • 15,159
  • 25
  • 75
  • 109

2 Answers2

25

Create multiple targets.

You can vary build configurations by right-clicking on a target and selecting Get Info. From there, you can do things like change which Info.plist file it's looking at (to do things like add "Lite" to the name and change the icon/load images) and set compiler flags so that you can #ifdef in places.

If there are lots of files that are only applicable in the full version, then you can right-click on them and remove them from the Lite target to make a smaller app.

I've experimented with various alternatives, such as multiple configurations, and I keep coming back to multiple targets. I usually have at least three defined - Development, Ad hoc and App Store, each with their own particular settings.

Jim
  • 72,985
  • 14
  • 101
  • 108
  • Jim - When you make a new target, do you have to copy over all files or only the files that are NOT common? For example, I have a slightly different screen file (.xib)...I basically want disable a button and add additional text to a label. So when I create a new target should I copy over the original (.xib) and make changes to that in the new target? – milesmeow Dec 23 '11 at 18:34
  • If the changes are that minor, I would provide a preprocessor macro in the build settings for each target, then use `#ifdef` to make the changes in code. – Jim Jan 18 '12 at 13:23
  • If there are more extensive differences, I'd create a directory for each target, and put a copy of the nib in each folder, enable each one for its own target. When the application bundle is created, Xcode ignores the original folder structure (by default) and copies the files for that target into a flat directory structure. As it will only copy one of the two files, you will end up with the correct nib. – Jim Jan 18 '12 at 13:23
  • If you check your current single target project, you will see that most files that are needed at runtime or that produce object code are enabled for that target. When you duplicate your existing target to create a new one, those files will also be enabled for the new target. This is correct - the two targets are independent of each other and they both need all the files. – Jim Jan 18 '12 at 13:25
15

Add an additional target to your Xcode project by duplicating the existing one. Define a macro in the new target (under "preprocessor macros" in build settings), something like "macroIsFreeVersion"

Now you can do this:

#ifdef macroIsFreeVersion
  // code that will only execute in the free version here
#endif

and this:

#ifndef macroIsFreeVersion
   // code for only the paid version goes here
#endif

You will need to make additional changes for the bundle id, provisioning profile, etc. All the stuff you did to put your paid version into the store.

William Jockusch
  • 26,513
  • 49
  • 182
  • 323
  • Hi William: I'm in XCode4 (also please bear with me bc this is the first time I'm trying to do this multitarget config and working with compiler flags). I have "Apple LLVM compiler 2.0 - Preprocessing" -> "Preprocessor Macros". Under that I have Debug, Release, MyProject. So to follow your example I would just put "macroIsFreeVersion" in these three fields? – milesmeow Dec 23 '11 at 23:40
  • Yes, though I've recently learned that you can also do it via the info dictionary -- the method is [[NSBundle mainBundle]infoDictionary]. Depending on your setup, this may or may not be a superior solution. – William Jockusch Dec 24 '11 at 11:20