0

xcodebuild has a parameter -userdefault=value. How can I use it to set NSUserDefaults ? Do I have to specify a file/plist?

durron597
  • 31,968
  • 17
  • 99
  • 158
Mann
  • 2,118
  • 1
  • 18
  • 18
  • I've never used it but it looks to have `name=value` semantics and it's not clear what user defaults are being changed... – trojanfoe Oct 03 '12 at 12:38

1 Answers1

1

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.

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).

See here in the documentation for more info (especially Table 1-2) and the paragraph "The Argument Domain".


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 its IndexOnOpen preference to NO:

    localhost> Xcode.app/Contents/MacOS/Xcode -IndexOnOpen NO

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.

AliSoftware
  • 32,623
  • 6
  • 82
  • 77