How do I configure full URLs in xcconfig files

IosIphoneXcodeBuild SettingsXcconfig

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

Here's a simple workaround:

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

Solution 2 - Ios

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}

Solution 3 - Ios

Just declare

SIMPLE_SLASH=/

Then your URL becomes

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

Solution 4 - Ios

SLASH=/

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

Solution 5 - Ios

Another approach that improves readability could be:

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

This way protocol can be used elsewhere

Solution 6 - Ios

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionatreatView Question on Stackoverflow
Solution 1 - IosDavid HView Answer on Stackoverflow
Solution 2 - IosMartin RView Answer on Stackoverflow
Solution 3 - IosMohGView Answer on Stackoverflow
Solution 4 - IosBadreView Answer on Stackoverflow
Solution 5 - Iosall.herranzView Answer on Stackoverflow
Solution 6 - IosCouchDeveloperView Answer on Stackoverflow