<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://commons.oreilly.com/wiki/index.php?title=Learning_Cocoa_with_Objective-C/Appendixes/Exercise_Solutions&amp;action=history&amp;feed=atom</id>
		<title>Learning Cocoa with Objective-C/Appendixes/Exercise Solutions - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://commons.oreilly.com/wiki/index.php?title=Learning_Cocoa_with_Objective-C/Appendixes/Exercise_Solutions&amp;action=history&amp;feed=atom"/>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Learning_Cocoa_with_Objective-C/Appendixes/Exercise_Solutions&amp;action=history"/>
		<updated>2013-05-23T18:04:40Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.11.0</generator>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Learning_Cocoa_with_Objective-C/Appendixes/Exercise_Solutions&amp;diff=6281&amp;oldid=prev</id>
		<title>Docbook2Wiki: Initial conversion from Docbook</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Learning_Cocoa_with_Objective-C/Appendixes/Exercise_Solutions&amp;diff=6281&amp;oldid=prev"/>
				<updated>2008-03-07T12:56:06Z</updated>
		
		<summary type="html">&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;
This appendix gives some tips, hints, and answers to the exercises found at the end of each chapter.&lt;br /&gt;
&lt;br /&gt;
== [[Learning Cocoa with Objective-C/Cocoa Overview and Foundation/Cocoa Development Tools|Chapter 2]] ==&lt;br /&gt;
&lt;br /&gt;
# Open a Finder window, and navigate to the ''/Developer/Applications''folder. Drag the Project Builder and Interface Builder icons to your Dock.&lt;br /&gt;
# Open a Finder window and navigate to the ''/Developer/Documentation/Cocoa''folder. Drag the ''CocoaTopics.html'' file to your Dock.&lt;br /&gt;
&lt;br /&gt;
== [[Learning Cocoa with Objective-C/Cocoa Overview and Foundation/Object-Oriented Programming with Objective-C|Chapter 3]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;One way to access the documentation:&lt;br /&gt;
&lt;br /&gt;
Open the ''/Developer/Documentation/Cocoa/CocoaTopics.html'' file in your web browser of choice, click on the Foundation link in the Objective-C Framework Reference section, and then follow the &amp;lt;tt&amp;gt;NSObject&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;NSString&amp;lt;/tt&amp;gt; links.&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;One way to find the documentation:&lt;br /&gt;
&lt;br /&gt;
In the Foundation reference document that the &amp;lt;tt&amp;gt;NSObject&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;NSString&amp;lt;/tt&amp;gt; links are on, go to the bottom of the page, and click on the Functions link. You'll find the &amp;lt;tt&amp;gt;NSLog&amp;lt;/tt&amp;gt; documentation on this page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;tip&amp;quot;&amp;gt;&lt;br /&gt;
'''Tip'''&lt;br /&gt;
&lt;br /&gt;
Use the Find functionality of your browser (Edit → Find, or [[Image:Learning Cocoa with Objective-C_I__tt614.png|]]-F on most browsers) to search for the &amp;lt;tt&amp;gt;NSLog&amp;lt;/tt&amp;gt; documentation on this rather large page.&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;One way to do it is to add the following line to the &amp;lt;tt&amp;gt;initWithName:artist:&amp;lt;/tt&amp;gt; method of the Song class:&lt;br /&gt;
&lt;br /&gt;
 NSLog(@&amp;quot;isa: %@ self %@&amp;quot;, isa, self);&lt;br /&gt;
&lt;br /&gt;
This will print the name of the class as well as the description.&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;
== [[Learning Cocoa with Objective-C/Cocoa Overview and Foundation/The Cocoa Foundation Kit|Chapter 4]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Here's one way to do it:&lt;br /&gt;
&lt;br /&gt;
Open the strings project we created, and place a breakpoint before the &amp;lt;tt&amp;gt;[artist&amp;lt;/tt&amp;gt; &amp;lt;tt&amp;gt;release]&amp;lt;/tt&amp;gt; statement. Debug the application, and enter in the following commands into the ''gdb'' console:&lt;br /&gt;
&lt;br /&gt;
 (gdb) '''print-object [artist lowercaseString]'''&lt;br /&gt;
 (gdb) '''print-object [artist uppercaseString]'''&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;One possible solution is to create a project named &amp;quot;fileprinter&amp;quot; with the following ''main.m'' file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;#import &amp;lt;Foundation/Foundation.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, const char * argv[]) {&lt;br /&gt;
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;'''    if (argc &amp;gt; 1) {'''&lt;br /&gt;
                      '''&amp;lt;nowiki&amp;gt;        NSString * filename = [NSString stringWithCString:argv[1]];&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                      '''        NSString * file = [NSString stringWithContentsOfFile:filename];'''&lt;br /&gt;
                      '''        printf(&amp;quot;%s\n&amp;quot;, [file UTF8String]);'''&lt;br /&gt;
                      '''    }'''&lt;br /&gt;
     [pool release];&lt;br /&gt;
     return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
When executed from Project Builder, nothing will happen, but if you go to the terminal and issue the following commands, you will see the contents of the ''main.m'' file printed:&lt;br /&gt;
&lt;br /&gt;
 [titanium:~] duncan% '''cd ~/LearningCocoa/fileprinter'''&lt;br /&gt;
 [titanium:~/LearningCocoa/fileprinter] duncan% '''build/fileprinter main.m'''&lt;br /&gt;
                   &lt;br /&gt;
&lt;br /&gt;
Try this with a few other files.&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;One way to look up this documentation:&lt;br /&gt;
&lt;br /&gt;
Open the ''/Developer/Documentation/Cocoa/CocoaTopics.html''file in your web browser of choice, click on the Foundation link in the Objective-C Framework Reference section, and then follow the &amp;lt;tt&amp;gt;NSArray&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;NSSet&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;NSDictionary&amp;lt;/tt&amp;gt; links.&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;One solution is to add the following line of code to the main method:&lt;br /&gt;
&lt;br /&gt;
                      '''[array writeToFile:@&amp;quot;foo.plist&amp;quot; atomically:YES];'''&lt;br /&gt;
                   &lt;br /&gt;
&lt;br /&gt;
When you run the arrays program with this additional line, a ''foo.plist'' file will be written into ''~/LearningCocoa/arrays/build'' containing the elements of the array.&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;One possible solution is to create a project named &amp;quot;dictionarysaver&amp;quot; with the following ''main.m'' file:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;#import &amp;lt;Foundation/Foundation.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, const char * argv[]) {&lt;br /&gt;
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;'''    NSMutableDictionary * dict = [NSMutableDictionary dictionary];'''&lt;br /&gt;
                      '''    [dict setObject:@&amp;quot;The Meaning of Life&amp;quot; forKey:@&amp;quot;A String&amp;quot;];'''&lt;br /&gt;
                      '''    [dict setObject:[NSNumber numberWithInt:42] forKey:@&amp;quot;An Integer&amp;quot;];'''&lt;br /&gt;
                      '''    [dict writeToFile:@&amp;quot;dict.plist&amp;quot; atomically:YES];'''&lt;br /&gt;
     [pool release];&lt;br /&gt;
     return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
When you run this program, the dictionary will be written to the ''dict.plist'' file in the ''~/LearningCocoa/dictionarysaver''folder. This file will look as follows:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE plist PUBLIC &amp;quot;-//Apple Computer//DTD PLIST 1.0//EN&amp;quot; &amp;quot;http://www.apple.&lt;br /&gt;
com/DTDs/PropertyList-1.0.dtd&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;plist version=&amp;quot;1.0&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;dict&amp;gt;&lt;br /&gt;
        &amp;lt;key&amp;gt;A String&amp;lt;/key&amp;gt;&lt;br /&gt;
        &amp;lt;string&amp;gt;The Meaning of Life&amp;lt;/string&amp;gt;&lt;br /&gt;
        &amp;lt;key&amp;gt;An Integer&amp;lt;/key&amp;gt;&lt;br /&gt;
        &amp;lt;integer&amp;gt;42&amp;lt;/integer&amp;gt;&lt;br /&gt;
&amp;lt;/dict&amp;gt;&lt;br /&gt;
&amp;lt;/plist&amp;gt;&amp;lt;/nowiki&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;The dictionaries example application doesn't release the &amp;lt;tt&amp;gt;dict&amp;lt;/tt&amp;gt; object. The following line of code is needed after the &amp;lt;tt&amp;gt;printf&amp;lt;/tt&amp;gt; statement:&lt;br /&gt;
&lt;br /&gt;
                      '''[dict release];'''&lt;br /&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;
== [[Learning Cocoa with Objective-C/Single-Window Applications/Graphical User Interfaces|Chapter 5]] ==&lt;br /&gt;
&lt;br /&gt;
# One way to do this is to select the text labels, then change the font using the Font Panel (Format → Show Fonts, or [[Image:Learning Cocoa with Objective-C_I__tt623.png|]]-T).&lt;br /&gt;
# One way to do this is to select the &amp;lt;tt&amp;gt;totalField&amp;lt;/tt&amp;gt;, then change the font color using the Font Panel. To access the color picker, use the Extras... pull-down menu on the Font Panel.&lt;br /&gt;
&lt;br /&gt;
== [[Learning Cocoa with Objective-C/Single-Window Applications/Windows, Views, and Controls|Chapter 6]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;The documentation can be found in the ''/Developer/Documentation/Cocoa /CocoaTopics.html''folder. Click on the Application Kit link in the Objective-C Framework Reference section, and then follow the &amp;lt;tt&amp;gt;NSWindow&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;NSView&amp;lt;/tt&amp;gt; links.&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;The easiest way to do this is to select the window in Interface Builder and change the title using the Attributes inspector. You can bring the inspector up by hitting Shift-[[Image:Learning Cocoa with Objective-C_I__tt624.png|]]-I.&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;One way to do this is to edit the ''Controller.h'' file directly to match the following code:&lt;br /&gt;
&lt;br /&gt;
 @interface Controller : NSObject&lt;br /&gt;
 {&lt;br /&gt;
     IBOutlet id converter;&lt;br /&gt;
 '''    IBOutlet NSTextField dollarField;'''&lt;br /&gt;
                      '''    IBOutlet NSTextField rateField;'''&lt;br /&gt;
                      '''    IBOutlet NSTextField totalField;'''&lt;br /&gt;
 }&lt;br /&gt;
 - (IBAction)convert:(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;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[Learning Cocoa with Objective-C/Single-Window Applications/Custom Views|Chapter 7]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;One way to do this is to edit the &amp;lt;tt&amp;gt;drawRect:&amp;lt;/tt&amp;gt; method as follows:&lt;br /&gt;
&lt;br /&gt;
 - (void)drawRect:(NSRect)rect&lt;br /&gt;
 {&lt;br /&gt;
 '''&amp;lt;nowiki&amp;gt;    [[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0] set];&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
     NSRectFill([self bounds]);&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;The easiest way to do this is to add the drawing code from the String View application into the Line View &amp;lt;tt&amp;gt;drawRect:&amp;lt;/tt&amp;gt; method as follows:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;- (void)drawRect:(NSRect)rect&lt;br /&gt;
{&lt;br /&gt;
    NSRect bounds = [self bounds];&lt;br /&gt;
    NSPoint bottom = NSMakePoint((bounds.size.width/2.0), 0);&lt;br /&gt;
    NSPoint top = NSMakePoint((bounds.size.width/2.0), bounds.size.height);&lt;br /&gt;
    NSPoint left = NSMakePoint(0, (bounds.size.height/2.0));&lt;br /&gt;
    NSPoint right = NSMakePoint(bounds.size.width, (bounds.size.height/2.0));&lt;br /&gt;
&lt;br /&gt;
    [[NSColor whiteColor] set];&lt;br /&gt;
    [NSBezierPath fillRect:bounds];&lt;br /&gt;
&lt;br /&gt;
    [[NSColor blackColor] set];&lt;br /&gt;
    [NSBezierPath strokeRect:bounds];&lt;br /&gt;
&lt;br /&gt;
    [NSBezierPath strokeLineFromPoint:top toPoint:bottom];&lt;br /&gt;
    [NSBezierPath strokeLineFromPoint:right toPoint:left];&lt;br /&gt;
&lt;br /&gt;
    [[NSBezierPath bezierPathWithOvalInRect:bounds] stroke];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;'''    NSString * hello = @&amp;quot;Hello World!&amp;quot;;'''&lt;br /&gt;
                      '''    NSMutableDictionary * attribs = [NSMutableDictionary dictionary];'''&lt;br /&gt;
                      '''    [attribs setObject:[NSFont fontWithName:@&amp;quot;Times&amp;quot; size:24]'''&lt;br /&gt;
                      '''                forKey:NSFontAttributeName];'''&lt;br /&gt;
                      '''    [attribs setObject:[NSColor redColor]'''               &lt;br /&gt;
                      '''                forKey:NSForegroundColorAttributeName];'''&lt;br /&gt;
                      '''    [hello drawAtPoint:NSMakePoint((bounds.size.width/2.0),'''&lt;br /&gt;
                      '''                                   (bounds.size.height/2.0))'''&lt;br /&gt;
                      '''        withAttributes:attribs];'''&lt;br /&gt;
   &lt;br /&gt;
 }&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;One way to do this is to insert the following line of code before drawing any of the lines in Line View:&lt;br /&gt;
&lt;br /&gt;
                      '''[NSBezierPath setDefaultLineWidth:3.0];'''&lt;br /&gt;
                   &lt;br /&gt;
&lt;br /&gt;
This will cause all paths to be drawn with 3-point-wide strokes. Try some other values.&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;One way of finding the &amp;lt;tt&amp;gt;NSBezierPath&amp;lt;/tt&amp;gt; documentation is to click the Find tab in Project Builder (or use the menu Find → Show Batch Find). Enter &amp;lt;tt&amp;gt;NSBezierPath&amp;lt;/tt&amp;gt; into the Find box, and hit Return. After a few moments, Project Builder will show you all the occurrences of the &amp;lt;tt&amp;gt;NSBezierPath&amp;lt;/tt&amp;gt; string, both in your project and in the frameworks against which it's linked. To limit the search to just your project, adjust the &amp;quot;This Project&amp;quot; pull-down to &amp;quot;This Project, no frameworks.&amp;quot;&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;
== [[Learning Cocoa with Objective-C/Single-Window Applications/Event Handling|Chapter 8]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;The easiest way to accomplish this is to rename the &amp;lt;tt&amp;gt;mouseDown:&amp;lt;/tt&amp;gt; method to &amp;lt;tt&amp;gt;mouseDragged:&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;One way to do this is to modify the &amp;lt;tt&amp;gt;initWithFrame:&amp;lt;/tt&amp;gt; method as follows:&lt;br /&gt;
&lt;br /&gt;
 - (id)initWithFrame:(NSRect)frame&lt;br /&gt;
 {&lt;br /&gt;
     self = [super initWithFrame:frame];&lt;br /&gt;
 '''    center.x = frame.size.width / 2.0;'''&lt;br /&gt;
                      '''    center.y = frame.size.height / 2.0;'''&amp;lt;nowiki&amp;gt;&lt;br /&gt;
    radius = 20.0;&lt;br /&gt;
    color = [[NSColor redColor] retain];&lt;br /&gt;
    return self;&lt;br /&gt;
}&amp;lt;/nowiki&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;One way of changing the &amp;lt;tt&amp;gt;setRadius:&amp;lt;/tt&amp;gt; method is as follows:&lt;br /&gt;
&lt;br /&gt;
                      '''- (IBAction)setRadius:(id)sender'''&lt;br /&gt;
                      '''{'''&lt;br /&gt;
                      '''    float newRadius = [sender floatValue];'''&lt;br /&gt;
                      '''    if (newRadius != radius) {'''&lt;br /&gt;
                      '''        radius = newRadius;'''&lt;br /&gt;
                      '''        [self setNeedsDisplay:YES];'''&lt;br /&gt;
                      '''    }'''&lt;br /&gt;
                      '''}'''&lt;br /&gt;
                   &lt;br /&gt;
&lt;br /&gt;
This will ensure that a redraw of the interface only occurs when it is needed.&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;One way to do this is to make the &amp;lt;tt&amp;gt;MyDelegate&amp;lt;/tt&amp;gt; object instance a delegate of &amp;lt;tt&amp;gt;NSApplication&amp;lt;/tt&amp;gt; and implement the &amp;lt;tt&amp;gt;applicationShouldTerminate:&amp;lt;/tt&amp;gt; method. To do this, Control-drag a connection from File's Owner to MyDelegate in Interface Builder, then add the following method to the &amp;lt;tt&amp;gt;MyDelegate&amp;lt;/tt&amp;gt; class:&lt;br /&gt;
&lt;br /&gt;
 - (NSTerminationReply)applicationShouldTerminate:(NSApplication *)sender&lt;br /&gt;
 {&lt;br /&gt;
     int answer = NSRunAlertPanel(@&amp;quot;Quit&amp;quot;, @&amp;quot;Are you sure?&amp;quot;,&lt;br /&gt;
                                 @&amp;quot;Quit&amp;quot;, @&amp;quot;Cancel&amp;quot;, nil);&lt;br /&gt;
     if (answer == NSAlertDefaultReturn) {&lt;br /&gt;
         return NSTerminateNow;&lt;br /&gt;
     } else {&lt;br /&gt;
         return NSTerminateCancel;&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;We suggest changing it to blue by modifying the &amp;lt;tt&amp;gt;initWithFrame:&amp;lt;/tt&amp;gt; method as follows:&lt;br /&gt;
&lt;br /&gt;
 - (id)initWithFrame:(NSRect)frame&lt;br /&gt;
 {&lt;br /&gt;
     self = [super initWithFrame:frame];&lt;br /&gt;
     center.x = frame.size.width / 2;&lt;br /&gt;
     center.y = frame.size.height / 2;&lt;br /&gt;
     radius = 20.0;&lt;br /&gt;
 '''&amp;lt;nowiki&amp;gt;    color = [[NSColor blueColor] retain];&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
     return self;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Of course you can change it to whatever color you please.&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;To do this requires setting the springs appropriately in Interface Builder.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Set the springs for the Dot View as shown in [[Learning Cocoa with Objective-C/Appendixes/Exercise Solutions#learncocoa2-APP-A-FIG-1|Figure A-1]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;learncocoa2-APP-A-FIG-1&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure A-1. Spring settings for Dot View'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Learning Cocoa with Objective-C_I__tt633.png|Spring settings for Dot View]]&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;Set the springs for the slider as shown in [[Learning Cocoa with Objective-C/Appendixes/Exercise Solutions#learncocoa2-APP-A-FIG-2|Figure A-2]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;learncocoa2-APP-A-FIG-2&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure A-2. Spring settings for Dot View's slider'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Learning Cocoa with Objective-C_I__tt634.png|Spring settings for Dot View's slider]]&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;Set the springs for the color well as shown in [[Learning Cocoa with Objective-C/Appendixes/Exercise Solutions#learncocoa2-APP-A-FIG-3|Figure A-3]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;learncocoa2-APP-A-FIG-3&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure A-3. Spring settings for Dot View's color well'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Learning Cocoa with Objective-C_I__tt635.png|Spring settings for Dot View's color well]]&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;
&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;
== [[Learning Cocoa with Objective-C/Single-Window Applications/Models and Data Functionality|Chapter 9]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Go into Interface Builder, and either edit the column header, either directly or using the inspector.&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;One way to do it is to make the &amp;lt;tt&amp;gt;MyDataSource&amp;lt;/tt&amp;gt; object instance a delegate of &amp;lt;tt&amp;gt;NSApplication&amp;lt;/tt&amp;gt; and implement the &amp;lt;tt&amp;gt;applicationShouldTerminate:&amp;lt;/tt&amp;gt; method. To do this, Control-drag a connection from File's Owner to MyDataSource in Interface Builder, then add the following method to the &amp;lt;tt&amp;gt;MyDataSource&amp;lt;/tt&amp;gt; class:&lt;br /&gt;
&lt;br /&gt;
 - (NSTerminationReply)applicationShouldTerminate:(NSApplication *)sender&lt;br /&gt;
 {&lt;br /&gt;
     int answer = NSRunAlertPanel(@&amp;quot;Quit&amp;quot;, @&amp;quot;Are you sure?&amp;quot;,&lt;br /&gt;
                                 @&amp;quot;Quit&amp;quot;, @&amp;quot;Cancel&amp;quot;, nil);&lt;br /&gt;
     if (answer == NSAlertDefaultReturn) {&lt;br /&gt;
         return NSTerminateNow;&lt;br /&gt;
     } else {&lt;br /&gt;
         return NSTerminateCancel;&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;The &amp;lt;tt&amp;gt;FoodItem&amp;lt;/tt&amp;gt; class needs a &amp;lt;tt&amp;gt;dealloc&amp;lt;/tt&amp;gt; method to release the &amp;lt;tt&amp;gt;name&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;price&amp;lt;/tt&amp;gt; variables.&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;
== [[Learning Cocoa with Objective-C/Document-Based Applications/Multiple Document Architecture|Chapter 10]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Once again, the documentation can be found in the ''/Developer/Documentation /Cocoa/CocoaTopics.html''file.&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;In the active target panel of Project Builder (Project → Edit Active Target), add a document type with the following settings:&lt;br /&gt;
&lt;br /&gt;
* Name: Property List&lt;br /&gt;
* Extensions: plist&lt;br /&gt;
* Document Class: MyDocument&lt;br /&gt;
&lt;br /&gt;
Build and run ([[Image:Learning Cocoa with Objective-C_I__tt637.png|]]-R) the application. You should be able to read and write ''plist'' files now.&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;The revert functionality doesn't work because the &amp;lt;tt&amp;gt;windowControllerDidLoadNib&amp;lt;/tt&amp;gt; method isn't called, and that is where we turn the contents of a file into a string to use. To fix this, edit the &amp;lt;tt&amp;gt;loadDataRepresentation:ofType:&amp;lt;/tt&amp;gt; method as follows:&lt;br /&gt;
&lt;br /&gt;
 - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)type&lt;br /&gt;
 {&lt;br /&gt;
    ''' if (textView){'''&lt;br /&gt;
                      '''&amp;lt;nowiki&amp;gt;        NSString * text = [[NSString alloc]initWithData:dataFromFile&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                      '''                                               encoding:NSUTF8StringEncoding];'''&lt;br /&gt;
                      '''        [textView setString:text];'''&lt;br /&gt;
                      '''        [text release];'''&lt;br /&gt;
                      '''    } else {'''&lt;br /&gt;
                      '''        dataFromFile = [data retain];'''&lt;br /&gt;
                      '''    }'''&lt;br /&gt;
                      '''    return YES;'''&lt;br /&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;
== [[Learning Cocoa with Objective-C/Document-Based Applications/Rich-Text Handling|Chapter 11]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;To turn on the ability for the TextView to handle graphics from within Interface Builder, simply click on the TextView, and bring up the Attributes inspector, as shown in [[Learning Cocoa with Objective-C/Appendixes/Exercise Solutions#learncocoa2-APP-A-FIG-4|Figure A-4]]. Simply click on the radio buttons, and then remove the corresponding lines of code from ''MyDocument.m''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;learncocoa2-APP-A-FIG-4&amp;quot;&amp;gt;&lt;br /&gt;
'''Figure A-4. TextView attribute inspector'''&lt;br /&gt;
&lt;br /&gt;
[[Image:Learning Cocoa with Objective-C_I__tt639.png|TextView attribute inspector]]&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;Add the following line to the &amp;lt;tt&amp;gt;awakeFromNib:&amp;lt;/tt&amp;gt; method:&lt;br /&gt;
&lt;br /&gt;
                      '''[textView setRulerVisible:YES];'''&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;One solution:&lt;br /&gt;
&lt;br /&gt;
Add a menu item named &amp;quot;Speak&amp;quot; to the File menu of the ''MainMenu.nib'' file. Connect the menu item to &amp;lt;tt&amp;gt;FirstResponder.startSpeaking&amp;lt;/tt&amp;gt; by Control-dragging a connection from the menu item to the First Responder icon. This makes our &amp;lt;tt&amp;gt;speakText&amp;lt;/tt&amp;gt; method obsolete, so it can be removed.&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;One way to do this is to modify the &amp;lt;tt&amp;gt;analyzeText:&amp;lt;/tt&amp;gt; method, as shown here:&lt;br /&gt;
&lt;br /&gt;
 - (IBAction)analyzeText:(id)sender&lt;br /&gt;
 {&lt;br /&gt;
     int count = 0;                                                       &lt;br /&gt;
     int fontChanges = -1;                                                &lt;br /&gt;
     id lastAttribute = nil;                                              &lt;br /&gt;
     NSTextStorage * storage = [textView textStorage];                    &lt;br /&gt;
     &lt;br /&gt;
     while (count &amp;lt; [storage length]) {                                   &lt;br /&gt;
         id attributeValue = [storage attribute:NSFontAttributeName&lt;br /&gt;
                                     atIndex:count&lt;br /&gt;
                              effectiveRange:nil];&lt;br /&gt;
         if (attributeValue != lastAttribute) {                           &lt;br /&gt;
             fontChanges++;&lt;br /&gt;
         }&lt;br /&gt;
         lastAttribute = attributeValue;                                  &lt;br /&gt;
         count++;                                                         &lt;br /&gt;
     }&lt;br /&gt;
      &lt;br /&gt;
     NSBeginAlertSheet(@&amp;quot;Analysis&amp;quot;,         // title                       // i                              &lt;br /&gt;
                       @&amp;quot;OK&amp;quot;,               // default button label&lt;br /&gt;
                       nil,                 // cancel button label&lt;br /&gt;
                       nil,                 // other button label&lt;br /&gt;
                       [textView window],   // document window&lt;br /&gt;
                       nil,                 // modal delegate&lt;br /&gt;
                       NULL,                // selector to method&lt;br /&gt;
                       NULL,                // dismiss selector&lt;br /&gt;
                       nil,                 // context info&lt;br /&gt;
 '''                      @&amp;quot;Font Changes %i\nCharacter Count %i&amp;quot;,'''&lt;br /&gt;
                      '''                      fontChanges, [storage length]);'''&lt;br /&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;
== [[Learning Cocoa with Objective-C/Miscellaneous Topics/Printing|Chapter 12]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;The easiest way to do this is to add the Font menu to the ''MainMenu.nib'' file. Then, in your application, use the Font menu to bring up the Font Panel (or hit [[Image:Learning Cocoa with Objective-C_I__tt642.png|]]-T).&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;This is almost a trick question.&lt;br /&gt;
&lt;br /&gt;
By default, the File → Print command works and will print out the Dot View window. To print just the Dot View, disconnect the File → Print menu item from &amp;lt;tt&amp;gt;FirstResponder.print&amp;lt;/tt&amp;gt;, then connect it (by Control-dragging) to the &amp;lt;tt&amp;gt;DotView&amp;lt;/tt&amp;gt; area and the &amp;lt;tt&amp;gt;print:&amp;lt;/tt&amp;gt; action.&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;Simply drag the image view to encompass the entire window. You may even want to turn the border off so that only the image contained by the view will print. Try setting the image view to some of the images in the ''/Library/Desktop Pictures'' folder for printing.&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;
== [[Learning Cocoa with Objective-C/Miscellaneous Topics/Bundles and Resources|Chapter 13]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;One way to do this:&lt;br /&gt;
&lt;br /&gt;
Add the following method to ''Controller.m'', and connect it to a &amp;quot;Previous Image&amp;quot; button:&lt;br /&gt;
&lt;br /&gt;
                      '''- (IBAction)prevousImage:(id)sender'''&lt;br /&gt;
                      '''{'''&lt;br /&gt;
                      '''    if (currentImage == 0) {'''&lt;br /&gt;
                      '''        currentImage = [images count] - 1;'''&lt;br /&gt;
                      '''    } else {'''&lt;br /&gt;
                      '''        currentImage--;'''&lt;br /&gt;
                      '''    }'''&lt;br /&gt;
                      '''    [imageView setImage objectAtIndex:currentImage];'''&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;One way to do this is in Interface Builder. In the inspector, set the key equivalent of the next button to &amp;quot;n&amp;quot; and of the previous button to &amp;quot;p&amp;quot;.&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;warning&amp;quot;&amp;gt;&lt;br /&gt;
'''Warning'''&lt;br /&gt;
&lt;br /&gt;
Be sure to hit Return after entering in the key equivalent so that it is stored in the nib file. We had a few problems with this feature on some builds of Interface Builder until we discovered this.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[Learning Cocoa with Objective-C/Miscellaneous Topics/Localization|Chapter 14]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;The best way to do this is to follow the procedure that we detailed in the chapter:&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 localized nib file variant.&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;Modify the various strings in the UI for their new language.&lt;br /&gt;
&lt;br /&gt;
If you don't know another language, or if you just want to check your translations, use the Translation channel of Sherlock 3.&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;
&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;
== [[Learning Cocoa with Objective-C/Miscellaneous Topics/Defaults and Preferences|Chapter 15]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Find the ''~/Library/Preferences/com.oreilly.Favorites'' file, and double-click it to open it in the Property List Editor (/''Developer/Applications'').&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 button on the interface for the Favorites application, and have it call the following action method:&lt;br /&gt;
&lt;br /&gt;
                      '''- (IBAction)reset:(id)sender'''&lt;br /&gt;
                      '''{'''&lt;br /&gt;
                      '''    [prefs removeObjectForKey:@&amp;quot;FavBook&amp;quot;];'''&lt;br /&gt;
                      '''    [prefs removeObjectForKey:@&amp;quot;FavCity&amp;quot;];'''&lt;br /&gt;
                      '''    [prefs removeObjectForKey:@&amp;quot;FavColor&amp;quot;];'''&lt;br /&gt;
                      '''    [prefs removeObjectForKey:@&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;One way to do this:&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 ''default.plist'' file using Property List Editor. The root key should be of type Dictionary, and it should have four children. The file should look as follows when you are done with it:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;!DOCTYPE plist SYSTEM &amp;quot;file://localhost/System/Library/DTDs/PropertyList.dtd&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;plist version=&amp;quot;0.9&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;dict&amp;gt;&lt;br /&gt;
     &amp;lt;key&amp;gt;FavBook&amp;lt;/key&amp;gt;&lt;br /&gt;
     &amp;lt;string&amp;gt;Learning Cocoa&amp;lt;/string&amp;gt;&lt;br /&gt;
     &amp;lt;key&amp;gt;FavCity&amp;lt;/key&amp;gt;&lt;br /&gt;
     &amp;lt;string&amp;gt;San Francisco &amp;lt;/string&amp;gt;&lt;br /&gt;
     &amp;lt;key&amp;gt;FavColor&amp;lt;/key&amp;gt;&lt;br /&gt;
     &amp;lt;string&amp;gt;Red&amp;lt;/string&amp;gt;&lt;br /&gt;
     &amp;lt;key&amp;gt;FavFood&amp;lt;/key&amp;gt;&lt;br /&gt;
     &amp;lt;string&amp;gt;Mexican&amp;lt;/string&amp;gt;&lt;br /&gt;
 &amp;lt;/dict&amp;gt;&lt;br /&gt;
 &amp;lt;/plist&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;Add the ''default.plist'' file as a resource to your project.&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 the &amp;lt;tt&amp;gt;init&amp;lt;/tt&amp;gt; method as follows:&lt;br /&gt;
&lt;br /&gt;
 - (id)init&lt;br /&gt;
 {&lt;br /&gt;
     [super init];&lt;br /&gt;
 '''&amp;lt;nowiki&amp;gt;    NSString file = [[NSBundle mainBundle]&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                            '''        pathForResource:@&amp;quot;default&amp;quot; ofType:@&amp;quot;plist];'''&lt;br /&gt;
                            '''    NSDictionary * defaultPrefs = [NSDictionary''' &lt;br /&gt;
                            '''        dictionaryWithContentsOfFile:file];'''&lt;br /&gt;
                            '''&amp;lt;nowiki&amp;gt;    prefs = [[NSUserDefaults standardUserDefaults] retain];&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                            '''    [prefs registerDefaults:defaultPrefs];'''&lt;br /&gt;
     return self;&lt;br /&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;
&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;One way to do this:&lt;br /&gt;
&lt;br /&gt;
Create a new action method in the ''Controller.h'' file as follows:&lt;br /&gt;
&lt;br /&gt;
                      '''- (IBAction)rateUpdated:(id)sender'''&lt;br /&gt;
                      '''{'''&lt;br /&gt;
                      '''&amp;lt;nowiki&amp;gt;    [[NSUserDefaults standardUserDefaults] setFloatValue:[sender floatValue]&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                      '''                                                 forKey:@&amp;quot;rate&amp;quot;];'''&lt;br /&gt;
                      '''}'''&lt;br /&gt;
                   &lt;br /&gt;
&lt;br /&gt;
Hook the &amp;lt;tt&amp;gt;rateField&amp;lt;/tt&amp;gt; text field to the &amp;lt;tt&amp;gt;rateUpdated:&amp;lt;/tt&amp;gt; action method so that it is called whenever the contents of the field are changed. Next, add an &amp;lt;tt&amp;gt;awakeFromNib&amp;lt;/tt&amp;gt; method to the ''Controller.h'' file as follows:&lt;br /&gt;
&lt;br /&gt;
                      '''- (void)awakeFromNib'''&lt;br /&gt;
                      '''{'''&lt;br /&gt;
                      '''&amp;lt;nowiki&amp;gt;    [rateField setFloatValue:[[NSUserDefaults standardUserDefaults]&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
                      '''        floatForKey:@&amp;quot;rate&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;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[Learning Cocoa with Objective-C/Miscellaneous Topics/Accessory Windows|Chapter 16]] ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;One way to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;div&amp;gt;Add an outlet named &amp;lt;tt&amp;gt;wordCountField&amp;lt;/tt&amp;gt; to the Controller class.&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 two text labels to the utility panel: the first named &amp;quot;Number of Words&amp;quot; and the second being a place holder. Connect the place holder to the &amp;lt;tt&amp;gt;wordCountField&amp;lt;/tt&amp;gt; outlet in the File's Owner object proxy.&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 the following code to the &amp;lt;tt&amp;gt;showInfoPanel:&amp;lt;/tt&amp;gt; method:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;#import &amp;quot;Controller.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
@implementation Controller&lt;br /&gt;
&lt;br /&gt;
- (IBAction)showInfoPanel:(id)sender&lt;br /&gt;
{&lt;br /&gt;
    if (!infoPanelController) {                                 &lt;br /&gt;
        [NSBundle loadNibNamed:@&amp;quot;InfoPanel&amp;quot; owner:self];            &lt;br /&gt;
        infoPanelController = [[NSWindowController alloc]           &lt;br /&gt;
            initWithWindow:infoPanel];&lt;br /&gt;
    }&lt;br /&gt;
    [textLengthField setIntValue:[[textView textStorage] length]];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;'''&amp;lt;nowiki&amp;gt;    [wordCountField setIntValue:[[textStorage&amp;lt;/nowiki&amp;gt;''' &lt;br /&gt;
                            '''        componentsSeparatedByString:@&amp;quot; &amp;quot;] count];'''  &lt;br /&gt;
     [infoPanelController showWindow:self];                          &lt;br /&gt;
 }&lt;br /&gt;
 @end&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;
&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;Follow the same process as listed earlier with a new &amp;lt;tt&amp;gt;paraCountField&amp;lt;/tt&amp;gt;, and separate the string based on the &amp;lt;tt&amp;gt;\n&amp;lt;/tt&amp;gt; character.&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;Use the following process to guide you:&lt;br /&gt;
&lt;br /&gt;
# Add a &amp;lt;tt&amp;gt;radiusTextField&amp;lt;/tt&amp;gt; outlet and a &amp;lt;tt&amp;gt;showInfoPanel:&amp;lt;/tt&amp;gt; action method to the DotView class.&lt;br /&gt;
# Create a new nib file named ''InfoPanel.nib''.&lt;br /&gt;
# Lay out a user interface that allows the radius to be displayed via a &amp;lt;tt&amp;gt;radiusTextField&amp;lt;/tt&amp;gt; outlet.&lt;br /&gt;
# Set the File's Owner of ''InfoPanel.nib'' to the DotView class.&lt;br /&gt;
# Add a menu item to the menu bar to show the Info panel, and connect it to the &amp;lt;tt&amp;gt;showInfoPanel:&amp;lt;/tt&amp;gt; action method.&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;
== [[Learning Cocoa with Objective-C/Miscellaneous Topics/Finishing Touches|Chapter 17]] ==&lt;br /&gt;
&lt;br /&gt;
We're going to leave the final exercises up to you to complete on your own. By now you should be able to tackle them without any help from us. However, here are a couple of ideas for an application to write:&lt;br /&gt;
&lt;br /&gt;
* A home inventory keeper that can keep a list of all the items in your house, complete with serial numbers and date of purchase&lt;br /&gt;
* An application that is like Dot View, but can draw shapes with a variable number of sides&lt;br /&gt;
&lt;br /&gt;
Good luck!&lt;/div&gt;</summary>
		<author><name>Docbook2Wiki</name></author>	</entry>

	</feed>