Question

I have an xcconfig file which contains a configuration for which server my app should hit. In debug mode, this will be a different server than for release builds.

The problem I have is that a URL of the form http://www.stackoverflow.com is treated as a comment after the double slash. So the string I get in code is 'http:'

I have read that I can put a -traditional build flag on Info.plist, I was wondering if someone else has had a similar issue and has solved it?

Thanks.

Was it helpful?

Solution

Here's a simple workaround:

WEBSITE_URL = https:/$()/www.example.com

OTHER TIPS

I also could not figure out how to use a double slash in a xcconfig file. But I found a workaround in

from the Xcode-users mailing list: In the xcconfigfile, save the URL without the http scheme:

MYURL = stackoverflow.com

In the Info.plist, set the property value to

http://${MYURL}

Just declare

SIMPLE_SLASH=/

Then your URL becomes

http:$(SIMPLE_SLASH)/www.stackoverflow.com
SLASH=/

API_URL=http:$(SLASH)/endpoint.com

Another approach that improves readability could be:

PROTOCOL = http:/
API_URL = $(PROTOCOL)/www.stackoverflow.com

This way protocol can be used elsewhere

You shouldn't use a xcconfig file for this setting.

A xcconfig file is not a "normal" header or module file which is the input of the preprocessor and eventually the input for the compiler. It's nowhere specified how the xcconfig file parser treats character encoding, whether it recognizes escape sequences, whether it expands macros, and how character literals are defined and much more.

It's far better in this case, to have a "config.h" header file and use a conditional based on a preprocessor definition:

#if defined (DEBUG)
    NSURL* url = ...
#else
    NSURL* url = ...
#endif

Here, DEBUG is defined for Debug configuration by default. You may #define any other definition in the build settings under "Preprocessor Macros".

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