How do I configure full URLs in xcconfig files

17.2k views Asked by At

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.

6

There are 6 answers

7
David H On BEST ANSWER

Here's a simple workaround:

WEBSITE_URL = https:/$()/www.example.com
2
Martin R On

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}
5
CouchDeveloper On

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".

0
all.herranz On

Another approach that improves readability could be:

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

This way protocol can be used elsewhere

1
MohG On

Just declare

SIMPLE_SLASH=/

Then your URL becomes

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

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