In my development I wish to hit a development URL when im testing but when the app is run on my iPhone, I want it to run on production URL. How do I get about setting this in Xcode?
Almost seems like I need to be able to set environmental variables (which in this case are different URLs).
Where do I set these up? Please hand hold me on the answer as I am fairly new
Thanks
There are lots of ways to do this. My preferred method is to create a file called Constants.h that looks like this:
//
// Constants.h
//
#ifndef Constants_h
#define Constants_h
#pragma mark - Instances
#ifdef DEVELOPMENT
#define ROOT_URL @"http://127.0.0.1:8000"
#endif
#ifdef STAGING
#define ROOT_URL @"http://staging.example.com"
#endif
#ifdef PRODUCTION
#define ROOT_URL @"http://production.example.com"
#endif
Then, I just include it in my *-Prefix.pch file like this:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "Constants.h"
#endif
In your build settings, set DEVELOPMENT, or STAGING, or PRODUCTION = 1.
Now you can access things like ROOT_URL anywhere in your project.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With