NSUserdefaults 使用 xcodebuild [英] NSUserdefaults using xcodebuild
问题描述
xcodebuild 有一个参数 -userdefault=value
.如何使用它来设置 NSUserDefaults
?我是否必须指定文件/plist?
xcodebuild has a parameter -userdefault=value
. How can I use it to set NSUserDefaults
? Do I have to specify a file/plist?
推荐答案
您只需将它用作 -name=value
语法,它定义 NSUserDefaults 中的值(在 NSArgumentDomain
级别),以便您可以使用 [[NSUserDefaults standardUserDefaults] valueForKey:@"name"]
以完全相同的方式检索它.
You simply use it as -name=value
syntax, and it defines the value in the NSUserDefaults (at the NSArgumentDomain
level) so that you can retrieve it using [[NSUserDefaults standardUserDefaults] valueForKey:@"name"]
exactly the same way you usually do.
这是一种覆盖其他域的默认值的方法,例如应用程序域中的默认值(由应用程序首选项的 plist 定义).
This is a way to override defaults value from other domains, like the defaults in the application domain (defined by the application preferences's plist).
请参阅文档中的此处 了解更多信息(尤其是表 1-2)和参数域"段落.
See here in the documentation for more info (especially Table 1-2) and the paragraph "The Argument Domain".
参数域包含从命令行参数设置的值(如果您从命令行启动应用程序)并由 NSArgumentDomain
常量标识.从命令行设置的值会被系统自动放置到这个域中.要向该域添加值,请在命令行上指定首选项名称(以连字符开头)并在其后添加相应的值.例如,以下命令启动 Xcode 并将其 IndexOnOpen
首选项的值设置为 NO
:
The Argument Domain
The argument domain comprises values set from command- line arguments (if you started the app from the command line) and is identified by the
NSArgumentDomain
constant. Values set from the command line are automatically placed into this domain by the system. To add a value to this domain, specify the preference name on the command line (preceded with a hyphen) and follow it with the corresponding value. For example, the following command launches Xcode and sets the value of itsIndexOnOpen
preference toNO
:
localhost> Xcode.app/Contents/MacOS/Xcode -IndexOnOpen NO
从命令行设置的首选项会暂时覆盖存储在用户默认数据库中的既定值.在前面的示例中,将 IndexOnOpen
首选项设置为 NO
可防止 Xcode 自动索引项目,即使该首选项在用户中设置为 YES
默认数据库.
Preferences set from the command line temporarily override the established values stored in the user’s defaults database. In the preceding example, setting the IndexOnOpen
preference to NO
prevents Xcode from indexing projects automatically, even if the preference is set to YES
in the user defaults database.
这篇关于NSUserdefaults 使用 xcodebuild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!