Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone project constant

I want to have a constant in my project to change between Lite and Pro version. I don't think it is the best way to do it, but I am trying to:

  1. add a constant in my app delegate

    #define BUILD_PRO 1 //0 => LITE, 1 => PRO
    
  2. when I need it I import the appDelegate and test it:

    #import "myAppDelegate.h"
    

    then later

    #if (BUILD_PRO==1)
    NSLog(@"this is pro version");
    #endif
    

The problem is that this code works in some files and don't works in others. I haven't found any explanation for this behaviour; does anyone have an explanation for it?

What is the right way to have two versions (pro and lite) from the same project?

like image 208
AmineG Avatar asked Aug 16 '26 14:08

AmineG


1 Answers

Yep. A pre-processor definition is the way to do it.

I imagine it is working in some files and not others because some might not be including your myAppDelegate.h file and therefore not getting the definition. I suggest defining a "Lite Version" and "Pro Version" target and setting the pre-processor variable in the build configuration for each target.

Once you have created a lite target (just select the duplicate target context menu item on your "Pro Version" target to create the lite one):

  • Go into the Project/Edit Target "Pro Version" menu item
  • Go to the build tab and find the Preprocessing section (towards the bottom).
  • add BUILD_PRO=1 to the "Preprocessing Macros" section.

That way you don't have to change any header files, you just need to build either the lite or full target. If you need to add pro functionality anywhere in your product just use:

#ifdef BUILD_PRO
// do some pro stuff
#endif
like image 189
RedBlueThing Avatar answered Aug 19 '26 02:08

RedBlueThing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!