xcode 如何在 xcconfig 文件中配置完整 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21317844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:35:02  来源:igfitidea点击:

How do I configure full URLs in xcconfig files

iosiphonexcodebuild-settingsxcconfig

提问by atreat

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.

我有一个 xcconfig 文件,其中包含我的应用程序应该访问的服务器的配置。在调试模式下,这将是与发布版本不同的服务器。

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

我遇到的问题是形式为http://www.stackoverflow.com的 URL被视为双斜杠后的注释。所以我在代码中得到的字符串是 '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?

我已经读到我可以在 Info.plist 上放置一个 -traditional build 标志,我想知道是否有人遇到过类似的问题并解决了它?

Thanks.

谢谢。

回答by David H

Here's a simple workaround:

这是一个简单的解决方法:

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

回答by Martin R

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

我也无法弄清楚如何在 xcconfig 文件中使用双斜杠。但我找到了一个解决方法

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

来自 Xcode-users 邮件列表:在xcconfigfile 中,保存不带 http 方案的 URL:

MYURL = stackoverflow.com

In the Info.plist, set the property value to

Info.plist 中,将属性值设置为

http://${MYURL}

回答by Mohamed Ghenania

Just declare

只需声明

SIMPLE_SLASH=/

Then your URL becomes

然后你的网址变成

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

回答by Badre

SLASH=/

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

回答by CouchDeveloper

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

您不应为此设置使用 xcconfig 文件。

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.

xcconfig 文件不是“正常”的头文件或模块文件,它是预处理器的输入并最终是编译器的输入。没有指定 xcconfig 文件解析器如何处理字符编码、是否识别转义序列、是否扩展宏以及如何定义字符文字等等。

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

在这种情况下,使用“config.h”头文件并使用基于预处理器定义的条件要好得多:

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

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

此处,DEBUG默认为 Debug 配置定义。您可以在“预处理器宏”下的构建设置中#define 任何其他定义。

回答by mergesort

You can use backslashes to escape:

您可以使用反斜杠来转义:

URL = "http:\/\/mydomain.com"

URL = "http:\/\/mydomain.com"

EDIT

编辑

Don't forget to Clean your project before re-build.

不要忘记在重新构建之前清理您的项目。