简体   繁体   English

如何通过命令行参数设置NSDictionary用户默认值?

[英]How to set an NSDictionary user default through a command line argument?

It's possible to set User Defaults in a Cocoa app by passing them on the command line as arguments like: 可以在Cocoa应用程序中设置用户默认值 ,方法是将它们作为参数传递给命令行:

> SomeApp -key value

This sets the default "key" to "value" in the NSArgumentDomain . NSArgumentDomain的默认"key""value"

Array defaults can be set by doing something like: 可以通过执行以下操作来设置数组默认值:

> SomeApp -key (element1,element2)

I've found that this will set an empty dictionary: 我发现这将设置一个空字典:

> SomeApp -key {}

... but I can't figure out how to set a dictionary containing elements. ...但我无法弄清楚如何设置包含元素的字典。 How can I set an NSDictionary user default through a command line argument? 如何通过命令行参数设置NSDictionary用户默认值?

It turns out the proper syntax is: > SomeApp -key {key1=value1;key2=value2;} 事实证明正确的语法是: > SomeApp -key {key1=value1;key2=value2;}

The array and dictionary syntax is similar to the output of NSArray and NSDictionary values when printed through NSLog() . 当通过NSLog()打印时,数组和字典语法类似于NSArrayNSDictionary值的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM