gpt4 book ai didi

ios - .xcconfig?如何设置环境变量

转载 作者:搜寻专家 更新时间:2023-10-31 08:21:37 24 4
gpt4 key购买 nike

我是 Xcode 新手。

在过去的两天里,我一直在研究如何在访问网络服务的 iPhone 上测试我的应用程序。在模拟器上,我可以使用硬编码的“localhost”变量,但我不想硬编码所有配置设置。

我使用的是 Swift + Xcode 6,但我认为这与 Xcode 5 的过程相同。

我看了很多文章,我想我应该使用 .xcconfig,但它很不清楚。

例如,我创建了一个Environment.xcconfig 文件。我用

填充它
API_BASE_URL = "http://localhost:4000/api/v1"

然后我进入 Project -> Info 并将 Debug 配置文件设置为 Environment

然后我尝试通过 ${API_BASE_URL} 访问代码中的变量,但我得到 Use of unresolved identifier 'API_BASE_URL'

这非常令人沮丧。有什么想法吗?

最佳答案

  1. 如果你有 pod 配置,设置配置层次结构: enter image description here

或者,如果您根本没有任何 pod,配置层次结构将如下所示: enter image description here

  1. 为每个配置文件创建所有键值对(在本例中有 3 个配置文件用于 dev/adhoc/appstore 构建)。每个配置文件都有相同的键集: enter image description here

  2. 将每个键添加到生成器: enter image description here

  3. 然后只需在您的代码中使用键: enter image description here

PS:以这种方式生成的 key 在 .swift 文件中也是可识别的(确保您的 Swift 项目中有一个桥接 header ,即使您不使用 obj-c 源并且它将是空的) .

Swift 2.2 更新:不再有效 Swift 2.2: GCC_PREPROCESSOR_DEFINITIONS constants no longer imported

关于ios - .xcconfig?如何设置环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24668284/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com