iphone:通过代码在Target的设置中获取User Defined变量? [英] iphone: get User Defined variable in Target's setting by code?
问题描述
我的项目有多个目标。每个目标都有自己的 Class
文件,用于设置内容。我想在目标设置( Info.plist
或Target的建筑设置)中存储 Class
名称。因此,我可以根据此设置定义我需要在每个目标中使用哪个类。
My project have multi-targets. Each target has its own Class
file for setting stuff. I want to store that Class
name in a target setting (Info.plist
or Target's Building setting). So that I can define which class I need to use in each target based on this setting.
根据这个问题,我把一个特定于目标的用户定义的
变量在每个Target的建筑设置中。
According to this question, I put "a target-specific User Defined
variable" in each Target's Building Setting.
但是不知道如何在我的代码中找回它?
But don't know how to get it back in my code?
推荐答案
由于Info.plist文件也经过预处理,您可以使用以下方法:
As the Info.plist file is preprocessed too, you can use this approach:
为示例CLASS_NAME定义构建设置中的用户定义设置。
和Info.plist文件的关键字。将密钥命名为CLASS_NAME,并将值设置为 $ {CLASS_NAME}
。
Define a User defined setting in your build settings, for Example CLASS_NAME.
And a key to your Info.plist-file. Name the key CLASS_NAME and set the value to ${CLASS_NAME}
.
然后,您可以通过以下方式访问此设置:
You can then access this setting by:
NSString* className = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CLASS_NAME"];
这篇关于iphone:通过代码在Target的设置中获取User Defined变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!