Errol
Errol

Reputation: 702

Xcode build settings to swap service URLs

I have a plist with a collection of URLs that my app utilizes.

I'd like to setup some sort of 1-click "scheme" or whatever within Xcode so that I can swap my app between the test server URLs and the live server URLs. I could either create a second plist with the test URLs or could do some string manipulation to change the host name after reading them.

How should I set this up? I'm starting from scratch here as I've never played with custom targets or anything.

Upvotes: 1

Views: 583

Answers (2)

Davyd Geyl
Davyd Geyl

Reputation: 4623

Create two different lists. You can use preprocessor macros to find out what configurations is used:

#ifdef DEBUG
    // use test URLs list
#else
    // use production URLs list
#endif

If you created the project in Xcode 4, it probably already has the DEBUG macro defined for Debug configuration. If you are not sure, go to Build Settings of the project and check the compiler preprocessing section. Preprocessor Macros row for Debug configuration should have DEBUG or DEBUG=1 string.

enter image description here

Upvotes: 2

FluffulousChimp
FluffulousChimp

Reputation: 9185

You are looking for the Other C flags build setting which can be set differently for different build configurations.

Something like: -DUSE_PRODUCTION_URLS=1

Here's a reference.

Upvotes: 0

Related Questions