It's possible to set User Defaults in a Cocoa app by passing them on the command line as arguments like:
> SomeApp -key value
This sets the default "key"
to "value"
in the NSArgumentDomain
.
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?
It turns out the proper syntax is: > 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()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.