xcode 使用 info.plist 为多目标应用程序存储特定于目标的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2989127/
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
Using info.plist for storing target-specific values for a multi-target app
提问by andybee
I have a multi-target iPhone app which currently includes a header file with constant definitions that are conditionally included at build time depending on which target is being built.
我有一个多目标 iPhone 应用程序,它当前包含一个带有常量定义的头文件,这些定义在构建时有条件地包含,具体取决于正在构建的目标。
However, I was wondering if it might be better to instead include this information in the info.plist for the build, as this generally holds target-specific meta, so logically seems more appropriate.
但是,我想知道将这些信息包含在构建的 info.plist 中是否更好,因为这通常包含特定于目标的元数据,因此在逻辑上似乎更合适。
Therefore, my questions are:
因此,我的问题是:
- Is it acceptable to include custom (non-Apple defined) keys in the info.plist file?
- Is this a suitable place to include meta for the app which differ between targets?
- 在 info.plist 文件中包含自定义(非 Apple 定义)键是否可以接受?
- 这是为不同目标的应用程序包含元数据的合适位置吗?
采纳答案by pgb
It is acceptable and suitable.
这是可以接受和合适的。
The Info.plist file is preprocessed (must be enabled in project settings by setting Packaging / Preprocess Info.plist File to Yes) by the C pre-processor, so you can have variables (in the form of ${VARIABLE_NAME}
). These variables can be defined in the User Defined
section in Xcode's target info, making it very easy to switch their value from one target to another.
Info.plist 文件由 C 预处理器预处理(必须在项目设置中通过将 Packaging / Preprocess Info.plist File 设置为 Yes 来启用),因此您可以拥有变量(以 的形式${VARIABLE_NAME}
)。这些变量可以User Defined
在 Xcode 的目标信息部分中定义,从而可以很容易地将它们的值从一个目标切换到另一个目标。