<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Learning Cocoa with Objective-C/Miscellaneous Topics/Defaults and Preferences - Revision history</title>
		<link>http://commons.oreilly.com/wiki/index.php?title=Learning_Cocoa_with_Objective-C/Miscellaneous_Topics/Defaults_and_Preferences&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.11.0</generator>
		<lastBuildDate>Wed, 22 May 2013 11:19:46 GMT</lastBuildDate>
		<item>
			<title>Docbook2Wiki: Initial conversion from Docbook</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Learning_Cocoa_with_Objective-C/Miscellaneous_Topics/Defaults_and_Preferences&amp;diff=6277&amp;oldid=prev</link>
			<description>&lt;p&gt;Initial conversion from Docbook&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Learning Cocoa with Objective-C/TOC}}&lt;br /&gt;
Most applications need to store and retrieve ''preferences'' that allow for user customization of an application's behavior and keep track of configuration settings. Mac OS X provides, as part of its Core Foundation framework, a preferences system that provides a simple and standard way to maintain these preferences. Cocoa calls these preferences ''defaults''.&lt;br /&gt;
&lt;br /&gt;
If you go to the ''~/Library/Preferences'' folder, you will see the user-preferences database used by the applications you run on your system. In fact, many of the applications we have created in this book have written preferences to this database. Take a look, and you'll see that you probably have ''Dot View.plist'', ''Menu.plist'', and ''RTF Edit.plist'' files. These contain preferences used by some of the various Cocoa base classes used in the sample applications we've built throughout the book.&lt;br /&gt;
&lt;br /&gt;
In this chapter we'll show you how to take advantage of the user-preferences system from your applications using Cocoa.&lt;br /&gt;
&lt;br /&gt;
== How Preferences Work ==&lt;br /&gt;
&lt;br /&gt;
The preference system in Mac OS X allows you to store values associated with a key—the name of a property—that can later be used to look up the preference value when you need it. These key-value pairs are scoped using a combination of username and application ID. All of the preferences for a user are stored in his ''~/Library /Preferences'' folder.&lt;br /&gt;
&lt;br /&gt;
There are multiple domains—or different scopes of coverage—in which a preference can exist. When you request a preference, the following resources are searched—in order—until a match is found:&lt;br /&gt;
&lt;br /&gt;
# The list of arguments that were passed to an application. This lets an application start up with a preference setting to override all other values for that preference's key.&lt;br /&gt;
# The users preferences stored in the ''~/Library/Preferences''folder. This is where preferences that are unique to a user and that need to last between invocations of an application are kept.&lt;br /&gt;
# A set of global preferences used across all applications that a user may use. For example, rulers in text views will obtain a user's preferred unit of measurement. These preferences are stored in the ''~/Library/Preferences/GlobalPreferences.plist''file. Many of these preferences are set using the System Preferences application.&lt;br /&gt;
# The set of preferences that your application registers as the defaults for your application. If a value for a preference is not found anywhere else, then this allows your application to provide a default value.&lt;br /&gt;
&lt;br /&gt;
Preferences in the ''~/Library/Preferences''folder are stored in the same property-list file format used by the ''Info.plist'' file included with application bundles. Preference value objects can be of any of the following types:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;NSString&amp;lt;/tt&amp;gt; for storing string values&lt;br /&gt;
* &amp;lt;tt&amp;gt;NSNumber&amp;lt;/tt&amp;gt; for storing number values derived from integers, floats, and other numeric types&lt;br /&gt;
* &amp;lt;tt&amp;gt;NSBoolean&amp;lt;/tt&amp;gt; for storing YES or NO values&lt;br /&gt;
* &amp;lt;tt&amp;gt;NSDate&amp;lt;/tt&amp;gt; for storing date information&lt;br /&gt;
* &amp;lt;tt&amp;gt;NSData&amp;lt;/tt&amp;gt; for storing arbitrary data&lt;br /&gt;
* &amp;lt;tt&amp;gt;NSArray&amp;lt;/tt&amp;gt; for storing arrays that consists of any of the previously listed types&lt;br /&gt;
* &amp;lt;tt&amp;gt;NSDictionary&amp;lt;/tt&amp;gt; for storing name/value dictionaries that have values of any of the previously listed types&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;warning&amp;quot;&amp;gt;&lt;br /&gt;
'''Warning'''&lt;br /&gt;
&lt;br /&gt;
While it is possible to edit the files in your ''~/Library/Preferences'' folder yourself using any text editor, you probably should not. You might introduce accidental errors into the XML syntax of the files. We'll see some other ways to edit these files in just a bit.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Defaults ==&lt;br /&gt;
&lt;br /&gt;
To show how to use the &amp;lt;tt&amp;gt;NSUserDefaults&amp;lt;/tt&amp;gt; class, the mechanism by which Cocoa provides access to Mac OS X's preference system, we'll build a simple application to keep track of a few of our favorite things.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Create a new Cocoa application project in Project Builder (File → New Project → Application → Cocoa Application) named &amp;quot;Favorites&amp;quot;, and save it in your ''~/LearningCocoa''folder.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Open the ''MainMenu.nib'' file in Interface Builder.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Lay out the user interface as shown in [[Learning Cocoa with Objective-C/Miscellaneous Topics/Defaults and Preferences#learncocoa2-CHP-15-FIG-1|Figure 15-1]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;learncocoa2-CHP-15-FIG-1&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure 15-1. Favorites application interface'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Learning Cocoa with Objective-C_I_4_tt540.png|Favorites application interface]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Create a subclass of &amp;lt;tt&amp;gt;NSObject&amp;lt;/tt&amp;gt; in Interface Builder. Click on the Classes tab of the MainMenu.nib window, find &amp;lt;tt&amp;gt;NSObject&amp;lt;/tt&amp;gt;, Control-click it, and select Subclass NSObject from the pop-up menu. Name the subclass &amp;quot;Controller&amp;quot;.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Create the following outlets on the Controller class:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;bookField&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;colorField&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;foodField&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;cityField&amp;lt;/tt&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Create an action named &amp;lt;tt&amp;gt;textFieldChanged:&amp;lt;/tt&amp;gt;. This action will tell the preferences database when an item has changed.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Generate the source-code files for the Controller class (Classes → Create Files for Controller).&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Instantiate the Controller class (Classes → Instantiate Controller).&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Connect the four text fields on the user interface to their respective outlets by control-dragging a connection from the Controller instance to each of the fields in turn.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Connect each of the four text fields to the Controller's &amp;lt;tt&amp;gt;textFieldChanged&amp;lt;/tt&amp;gt; action method by control-dragging a connection from the text field to the Controller instance.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Save (File → Save, or [[Image:Learning Cocoa with Objective-C_I_4_tt541.png|]] -S) the nib file, and return to Project Builder.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Edit the ''Controller.h''file as shown, adding an instance variable that will hold a reference to a &amp;lt;tt&amp;gt;NSUserDefaults&amp;lt;/tt&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
 #import &amp;lt;Cocoa/Cocoa.h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 @interface Controller : NSObject&lt;br /&gt;
 {&lt;br /&gt;
     IBOutlet id bookField;&lt;br /&gt;
     IBOutlet id cityField;&lt;br /&gt;
     IBOutlet id colorField;&lt;br /&gt;
     IBOutlet id foodField;&lt;br /&gt;
 '''    NSUserDefaults * prefs;'''&lt;br /&gt;
 }&lt;br /&gt;
 - (IBAction)textFieldChanged:(id)sender;&lt;br /&gt;
 @end&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Add an &amp;lt;tt&amp;gt;init&amp;lt;/tt&amp;gt; method to the ''Controller.m'' file. This will set the &amp;lt;tt&amp;gt;prefs&amp;lt;/tt&amp;gt; instance variable.&lt;br /&gt;
&lt;br /&gt;
                      '''- (id)init'''&lt;br /&gt;
                      '''{'''&lt;br /&gt;
                      '''    [super init];'''&lt;br /&gt;
                      '''    NSMutableDictionary * defaultPrefs = [NSMutableDictionary dictionary];   // a'''&lt;br /&gt;
 &lt;br /&gt;
                      '''    [defaultPrefs setObject:@&amp;quot;Learning Cocoa&amp;quot; forKey:@&amp;quot;FavBook&amp;quot;];            // b'''&lt;br /&gt;
                      '''    [defaultPrefs setObject:@&amp;quot;San Francisco&amp;quot; forKey:@&amp;quot;FavCity&amp;quot;];'''               &lt;br /&gt;
                      '''    [defaultPrefs setObject:@&amp;quot;Red&amp;quot; forKey:@&amp;quot;FavColor&amp;quot;];'''                        &lt;br /&gt;
                      '''    [defaultPrefs setObject:@&amp;quot;Mexican&amp;quot; forKey:@&amp;quot;FavFood&amp;quot;];'''                     &lt;br /&gt;
 &lt;br /&gt;
                      '''&amp;lt;nowiki&amp;gt;    prefs = [[NSUserDefaults standardUserDefaults] retain];                  // c&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                      '''    [prefs registerDefaults:defaultPrefs];                                   // d'''&lt;br /&gt;
 &lt;br /&gt;
                      '''    return self;'''    &lt;br /&gt;
                      '''}'''&lt;br /&gt;
                   &lt;br /&gt;
&lt;br /&gt;
This code does the following things:&lt;br /&gt;
&lt;br /&gt;
# Creates a new mutable dictionary that will serve as the container for the default values the application will use&lt;br /&gt;
# Sets four key/value pairs that correspond to the default values we want to store in the preferences system&lt;br /&gt;
# Obtains a reference to the preferences system&lt;br /&gt;
# Indicates to the &amp;lt;tt&amp;gt;prefs&amp;lt;/tt&amp;gt; object that we want to use the &amp;lt;tt&amp;gt;defaultPrefs&amp;lt;/tt&amp;gt; dictionary as the set of default preferences&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Add a &amp;lt;tt&amp;gt;dealloc&amp;lt;/tt&amp;gt; method so that the class cleans up after itself properly.&lt;br /&gt;
&lt;br /&gt;
                      '''- (void)dealloc'''&lt;br /&gt;
                      '''{'''&lt;br /&gt;
                      '''    [prefs release];'''&lt;br /&gt;
                      '''    [super dealloc];'''&lt;br /&gt;
                      '''}'''&lt;br /&gt;
                   &lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Add an &amp;lt;tt&amp;gt;awakeFromNib&amp;lt;/tt&amp;gt; method to populate the user interface from any settings that are in the &amp;lt;tt&amp;gt;prefs&amp;lt;/tt&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
                      '''- (void)awakeFromNib'''&lt;br /&gt;
                      '''{'''&lt;br /&gt;
                      '''&amp;lt;nowiki&amp;gt;    [bookField setStringValue:[prefs stringForKey:@&amp;quot;FavBook&amp;quot;]];&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                      '''&amp;lt;nowiki&amp;gt;    [cityField setStringValue:[prefs stringForKey:@&amp;quot;FavCity&amp;quot;]];&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                      '''&amp;lt;nowiki&amp;gt;    [colorField setStringValue:[prefs stringForKey:@&amp;quot;FavColor&amp;quot;]];&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                      '''&amp;lt;nowiki&amp;gt;    [foodField setStringValue:[prefs stringForKey:@&amp;quot;FavFood&amp;quot;]];&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                      '''}'''&lt;br /&gt;
                   &lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Implement the &amp;lt;tt&amp;gt;textFieldChanged:&amp;lt;/tt&amp;gt; action method so that the key values are saved as they change to the &amp;lt;tt&amp;gt;prefs&amp;lt;/tt&amp;gt; object.&lt;br /&gt;
&lt;br /&gt;
 - (IBAction)textFieldChanged:(id)sender&lt;br /&gt;
 {&lt;br /&gt;
 '''    if (sender == bookField) {'''&lt;br /&gt;
                      '''        [prefs setObject:[bookField stringValue] forKey:@&amp;quot;FavBook&amp;quot;];'''&lt;br /&gt;
                      '''    } else if (sender == cityField) {'''&lt;br /&gt;
                      '''        [prefs setObject:[cityField stringValue] forKey:@&amp;quot;FavCity&amp;quot;];'''&lt;br /&gt;
                      '''    } else if (sender == colorField) {'''&lt;br /&gt;
                      '''        [prefs setObject:[colorField stringValue] forKey:@&amp;quot;FavColor&amp;quot;];'''&lt;br /&gt;
                      '''    } else if (sender == foodField ){'''&lt;br /&gt;
                      '''        [prefs setObject:[foodField stringValue] forKey:@&amp;quot;FavFood&amp;quot;];'''&lt;br /&gt;
                      '''    }'''&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Build and run ([[Image:Learning Cocoa with Objective-C_I_4_tt547.png|]]-R) the application. You should see the interface launch as shown in [[Learning Cocoa with Objective-C/Miscellaneous Topics/Defaults and Preferences#learncocoa2-CHP-15-FIG-2|Figure 15-2]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;learncocoa2-CHP-15-FIG-2&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure 15-2. Our application running'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Learning Cocoa with Objective-C_I_4_tt548.png|Our application running]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Change some of the values. Quit the application, then restart to see if the values were saved.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Find the ''Favorites.plist'' file in your ''~/Library/Preferences''folder. Double-click the file to launch the Property List Editor (''/Applications/Utilities''), which allows you to see the values that you changed in the file, as shown in [[Learning Cocoa with Objective-C/Miscellaneous Topics/Defaults and Preferences#learncocoa2-CHP-15-FIG-3|Figure 15-3]]. To see the XML representation of the ''plist'' file, click the Dump button. You can also, if needed, edit the property list here, save the changes, and then launch the application we built to see the changes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;learncocoa2-CHP-15-FIG-3&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure 15-3. The preferences file under the hood'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Learning Cocoa with Objective-C_I_4_tt549.png|The preferences file under the hood]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;sidebar&amp;quot;&amp;gt;&lt;br /&gt;
'''Overriding Preferences Using Launch Arguments'''&lt;br /&gt;
&lt;br /&gt;
Sometimes, when you are developing an application, it is useful to override preference settings for a particular run of an application. To do this, simply specify the preference key names and values as launch arguments when you launch your application from the Terminal. These arguments are given following the pattern:&lt;br /&gt;
&lt;br /&gt;
 Application -[''Key name''] [''Value name''] ...&lt;br /&gt;
&lt;br /&gt;
For example, to override the favorite city when we launch the Favorites application, enter the following command into a Terminal window:&lt;br /&gt;
&lt;br /&gt;
 open ~/LearningCocoa/Favorites/build/Favorites.app - FavCity &amp;quot;New Orleans&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Of course, you can apply this concept to any application on your system as long as you know the name of the preference to use. The best way to find out preference names is to look in the ''plist'' files that they leave in the ''~/Library/Preferences''folder.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Command-Line Preferences Access ==&lt;br /&gt;
&lt;br /&gt;
You can access your preferences from the Terminal by using the ''defaults'' command. For example, to see the defaults for the Favorites application we just built, type the following into a Terminal window:&lt;br /&gt;
&lt;br /&gt;
                '''defaults read Favorites'''&lt;br /&gt;
             &lt;br /&gt;
&lt;br /&gt;
Something like the following should print:&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     FavBook = &amp;quot;Stranger in a Strange Land&amp;quot;; &lt;br /&gt;
     FavCity = &amp;quot;Dallas Texas&amp;quot;; &lt;br /&gt;
     FavColor = Black; &lt;br /&gt;
     FavFood = Thai; &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
If you want to modify a preference from the command line, you can use the ''defaults''command's ''write'' option. For example, to change our favorite city to Sedona, Arizona, issue the following command (the quotes are needed to accommodate the comma in the value string we are using):&lt;br /&gt;
&lt;br /&gt;
                '''defaults write Favorites FavCity &amp;quot;Sedona, Arizona&amp;quot;'''&lt;br /&gt;
             &lt;br /&gt;
&lt;br /&gt;
Now go back to Project Builder, and build and run ([[Image:Learning Cocoa with Objective-C_I_4_tt555.png|]]-R) the Favorites application again to see the changes.&lt;br /&gt;
&lt;br /&gt;
== Using Unique Application Identifiers ==&lt;br /&gt;
&lt;br /&gt;
As we said before, preferences are stored in files using an application's ID. So far, our sample applications haven't specified a particular application ID, so the system has used the name of the application as its ID.&lt;br /&gt;
&lt;br /&gt;
However, when you browse through your ''~/Library/Preferences'' folder, you'll see that quite a few of the files have long names like ''com.apple.iPhoto.plist''. When Apple created the iPhoto application, they assigned it an application ID of ''com.apple.iPhoto—''Apple's domain name followed by the application name—to reduce the possibility of somebody else's application named iPhoto interfering with the preferences used by the system. Obviously, for an application like iPhoto, there probably won't be a collision. But for applications with more common names—like the ones that we have been creating in this book—this level of namespace protection is valuable.&lt;br /&gt;
&lt;br /&gt;
For example, all of the Mac OS X applications created by O'Reilly &amp;amp; Associates should have application IDs that start with ''com.oreilly''. Following this logic, our Favorites application should have an application ID of ''com.oreilly.Favorites''. To specify this application ID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Open up the main target of the application, navigate the outline view to Info.plist Entries → Simple View → Basic information, and change the Identifier field, as shown in [[Learning Cocoa with Objective-C/Miscellaneous Topics/Defaults and Preferences#learncocoa2-CHP-15-FIG-4|Figure 15-4]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;learncocoa2-CHP-15-FIG-4&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure 15-4. Setting the application identifier'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Learning Cocoa with Objective-C_I_4_tt556.png|Setting the application identifier]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Build and run ([[Image:Learning Cocoa with Objective-C_I_4_tt557.png|]]-R) the application, change the values, and quit the application.&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Using the Finder, you can see that there is now a ''com.oreilly.Favorites.plist''file in your ''~/Library/Preferences''folder. If you wanted to read this file from the command line, you could use the following command:&lt;br /&gt;
&lt;br /&gt;
 defaults read com.oreilly.Favorites&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&lt;br /&gt;
# Take a look at the contents of the Favorites preference list file using Property List Editor.&lt;br /&gt;
# Add a reset button to the Favorites application that will reset the values to their original state.&lt;br /&gt;
# Modify the Favorites application so that it reads its application defaults from a ''.plist'' file contained as a resource in its application bundle.&lt;br /&gt;
# Modify the Currency Converter application from [[Learning Cocoa with Objective-C/Single-Window Applications/Graphical User Interfaces|Chapter 5]] to remember the exchange rate between invocations of the application.&lt;/div&gt;</description>
			<pubDate>Fri, 07 Mar 2008 12:56:06 GMT</pubDate>			<dc:creator>Docbook2Wiki</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Learning_Cocoa_with_Objective-C/Miscellaneous_Topics/Defaults_and_Preferences</comments>		</item>
	</channel>
</rss>