O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

User Defaults

Cocoa’s NSUserDefaults class can also be used as a crude form of command-line processing. NSUserDefaults automatically takes parameters of the form -parameter value and adds them to the defaults domain NSArgumentDomain. Every parameter must take a single argument. You cannot have optional arguments or parameters with no arguments when using this technique.

This is a volatile domain, so its values will not be saved to the user preferences. You probably do not want to use NSUserDefaults as the main configuration interface for command-line programs because it is inflexible, but it can be useful when you want to supply some optional command-line options. This is handy for supplying debugging or testing flags to a GUI program.

Example 4.4 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required