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

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.