14 User Defaults

Many applications allow you, as the user, to configure their behavior or appearance. Cocoa provides a simple means of storing such preferences in the user’s defaults database.

NSUserDefaults

The NSUserDefaults class is your interface to the user’s defaults database. With it you can register factory defaults, set the user’s defaults, and read the defaults back out as needed. You can think of it as a very fancy dictionary.

Your application can register a set of defaults “from the factory.” These are the defaults that your application uses when users have not made their own configuration selections. These factory defaults are registered programmatically every time your application is launched.

When ...

Get Cocoa Programming for OS X: 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.