I have a little issue with Xcode and was wondering if anybody has this solved in a clever way?
Scenario:
- Two developers working on an iOS app.
- Single Xcode project hosted on GitHub.
- I have three configurations: Debug, TestFlight and Release.
- For at least the Release versions I want the hostname of our web services API to be compiled into the app.
I have code like this in out API wrapper:
#ifdef CONFIGURATION_Debug
static NSString * const kAPIBaseURLString = @"http://10.10.10.41:8080/api";
#elif CONFIGURATION_TestFlight
static NSString *const kAPIBaseURLString = @"http://9.9.9.9.eu-west1.compute.amazonaws.com:8080/api";
#elif CONFIGURATION_Release
static NSString * const kAPIBaseURLString = @"http://some.production.server";
#else
static NSString * const kAPIBaseURLString = @"http://error-crazy-configuration-must-be-set-in-xcode";
#endif
This all works great, however, there is a Git battle between the developers about the DEBUG string. Each points to our own dev lab and the file is constantly being checked in as either one address or the next. Its a pain.
I don’t want to have git “assume-nochanges” as there is important code changed regularly in this class.
I have thought about passing in the hostname as an arg, but that also causes changes to the project structure that git sees.
Any brainwaves on how to allow us to set the hostname without out getting Xcode or git in a twist?
Use schemes in Xcode.
For the Run configuration, add an environment variable:
For the Release configuration, add the same environment variable:
…and etcetera etcetera for the rest of your build configurations.
Under Manage Schemes, ensure the Shared checkbox is unchecked.
In your code, access the environment variable using:
As long as you’re not using shared schemes, all users can set their own environment variables/custom endpoints.