Question

I should built and archive my application with Prod_URL and Stage_URL for our test team. now i am using an Constant.h file and there is a code like;

//for stage
#define SERVICE_URL @"myStageUrl.com"
/*
//for prod
#define SERVICE_URL @"myProdUrl.com"
*/

And I always changing comment out lines to be able to build two different version of my app.

So now I wanna do it automatically.

I create two target like MyAppStage and MyAppProd. And I think I should write a Run Script for that to switch between these two #define lines. But I don't know how to write script.

Or are there any better way for that situation?

Thx,

Was it helpful?

Solution

If you have two separate targets you can place these defines in the project properties its self. To do that you go to your project properties. Click on the target you want to edit, click on the "Build Settings" tab and search for Preprocessor Macros. Define anything you want there and it will be visible for every class in that target.

Another option is to use the same Preprocessor Macros build setting and set a macro for STAGE. then in your Constant.h you can have something like:

//for stage
#ifdef STAGE
#define SERVICE_URL @"myStageUrl.com"
#else
//for prod
#define SERVICE_URL @"myProdUrl.com"
#endif

OTHER TIPS

In your target for staging, add a preprocessor macro, something like STAGING_BUILD will do. Don't change the production target.

Now, in your code:

#ifdef STAGING_BUILD

//for stage
#define SERVICE_URL @"myStageUrl.com"

#else

//for prod
#define SERVICE_URL @"myProdUrl.com"

#endif

then only the required line will be compiled in based on the target selected to be built.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top