Skip to content
CodeWorth
CodeWorth

Code worths when shared

Primary Navigation Menu
Menu
  • BLOG
    • DataBase
    • Programming
    • Mobile
    • Multimedia
    • OS Tips
    • Others
    • Web Development
  • Products
    • Utilities
    • Games
    • JsGenLib
      • PlugIns
      • Core Functions
      • Helper & ShortHands
  • About

IOS Distinguish between targets using Pre-processor Macros,

On June 18, 2012
In Mobile
Tagged ios
With 0 Comments
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
Well. that’s good to extend the business. however, once you make the app into paid, the users must have to pay for looking into it. Most users wont prefer buying paid one usless they look into 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
The following is the guide to maintain multiple products in same source base

Step – 1
  • Inorder to create seperate target you need to duplicate target from existing target using the steps given here
Step – 2
  • Go to new target’s build settings
  • Search for word “Prepro”
  • In setting named “Preprocessor Macros” add the desired macro (“Lite” in this case)
Step – 3
  • 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
Download the source

Download Sample Code
And finally the output of sample app is
  • Toolset (paid) Toolset Lite (free/lite)
2012-06-18

Subscribe

Enter your email address to receive notifications about new posts via email.

Join 634 other subscribers

Google

Designed using Chromatic WordPress Theme. Powered by WordPress.