How do you switch your app between a staging URL (for development and testing) and a production URL (for real world use)? I’ve changed my mind about my approach, because one size doesn’t fit all.
In 9 Code Smells of Preprocessor Use, I originally suggested that instead of using the preprocessor, it would be better to use a plist. Here’s the preprocessor code smell:
static NSString *const fooServiceURL = @"https://dev.foo.com/services/fooservice";
static NSString *const fooServiceURL = @"https://foo.com/services/fooservice";
I wrote, “Instead of defining these URLs in your code, treat them as resource definitions and place them in a plist, organized by type.”
I still think this is a good approach for a complicated app that talks to many services. Putting all the URLs in a plist makes them easy to find and manage.
But for a simple app, I’ve found this to be overkill. Instead, I create a class for the URLs, and access them through methods:
DebugSettings *debugSettings = [self debugSettings];
if ([debugSettings usingStaging])
The plist approach also makes it harder to switch between staging and production on the fly, because all the URLs have to be reloaded. With the “define it in code” approach, all I have to do to switch URLs is change a property in DebugSettings.
What about you? How do you switch your app between a staging URL and a production URL?