Preprocessor Macro : Pre-Processor refers to Pre-Processing or Pre-compiling & Macro is nothing but a function or constant defined in C. Logically PreProcessor Macro is nothing but a macro defined before proceeding to compile the actual code.
Well let’s look into the topic. Consider,
- You have been working on a IOS application named iSample
- You have released some 5 versions for free with some basic features.
- After that you have decided to extend the revenue by making into paid app and adding some new features on it
So, The better idea is to provide a free/lite version named iSample Free/iSample Lite to let the user download and use the basic functions.
From the developer point of view if he choosen to maintain source in two different repositories, it will be harder for him to sync up between paid and lite versions.
So, Let’s not choose to use different sources instead it will be nice if we do as following
- Create a seperate target for free/lite version
- Add a preprocessor named Free/Lite to it
- Distinguish the original target(paid) and new target(free) using pre-processor macro
Step – 1
- Inorder to create seperate target you need to duplicate target from existing target using the steps given here
- Go to new target’s build settings
- Search for word “Prepro”
- In setting named “Preprocessor Macros” add the desired macro (“Lite” in this case)
- Go to source and use either of following blocks
#ifdef Lite //do something when macro "Lite" is defined #else //source is running normal target #endif
(OR)#ifndef Lite //do something when macro "Lite" is not defined #endif
- The code should look something like in following image where some features are excluded on lite version
-
Toolset (paid) Toolset Lite (free/lite)