<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>theMikeSwan's Weblog</title>
	<atom:link href="http://themikeswan.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://themikeswan.wordpress.com</link>
	<description>Programming, Lighting, &#38; whatever</description>
	<lastBuildDate>Wed, 21 Dec 2011 22:43:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='themikeswan.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>theMikeSwan's Weblog</title>
		<link>http://themikeswan.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://themikeswan.wordpress.com/osd.xml" title="theMikeSwan&#039;s Weblog" />
	<atom:link rel='hub' href='http://themikeswan.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Updated version of Expenses Part 1</title>
		<link>http://themikeswan.wordpress.com/2011/08/02/updated-version-of-expenses-part-1/</link>
		<comments>http://themikeswan.wordpress.com/2011/08/02/updated-version-of-expenses-part-1/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 04:29:28 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/?p=109</guid>
		<description><![CDATA[I have posted the update version to the first part of my tutorial on Core Data. This version of the tutorial covers Xcode 4, mostly covering the bindings portion since the prototyping tool didn&#8217;t make it into Xcode 4. You can read the post here. As a reminder I will not be adding any tutorials [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=109&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have posted the update version to the first part of my tutorial on Core Data. This version of the tutorial covers Xcode 4, mostly covering the bindings portion since the prototyping tool didn&#8217;t make it into Xcode 4. You can read the post <a href="http://www.themikeswan.com/blog/?p=81">here</a>. As a reminder I will not be adding any tutorials to this site anymore as I have moved my blog to my main development website <a href="http://www.themikeswan.com">theMikeSwan.com</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=109&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2011/08/02/updated-version-of-expenses-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>
	</item>
		<item>
		<title>Blog moving</title>
		<link>http://themikeswan.wordpress.com/2011/07/20/blog-moving/</link>
		<comments>http://themikeswan.wordpress.com/2011/07/20/blog-moving/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 19:48:41 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/?p=84</guid>
		<description><![CDATA[This is just a quick note to let you all know I have moved my blog to one of my domains. It is now at http://www.theMikeSwan.com/blog. Now that Lion has been officially released I plan to update the tutorials for Lion &#38; Xcode 4.1 (I should have some time next week). All of these updates [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=84&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is just a quick note to let you all know I have moved my blog to one of my domains. It is now at <a href="http://www.theMikeSwan.com/blog" title="http://www.theMikeSwan.com/blog">http://www.theMikeSwan.com/blog</a>. Now that Lion has been officially released I plan to update the tutorials for Lion &amp; Xcode 4.1 (I should have some time next week). All of these updates will appear only on my new blog! I will add a note to each of the posts here as they get updated on the new site for the sake of those that find them through Google.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=84&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2011/07/20/blog-moving/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>
	</item>
		<item>
		<title>Expenses Part 5: Printing Core Data</title>
		<link>http://themikeswan.wordpress.com/2010/08/05/expenses-part-5-printing-core-data/</link>
		<comments>http://themikeswan.wordpress.com/2010/08/05/expenses-part-5-printing-core-data/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 04:25:13 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Core Data]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/?p=86</guid>
		<description><![CDATA[Update 21 Dec 2011: I have added the classes mentioned here to an open source repo on GitHub. You can find it at https://github.com/theMikeSwan/TMSSupportClasses. There is also a class to help with implementing iCloud for Mac OS X. Over time I will be adding more support classes and I will add blog posts for them [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=86&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Update 21 Dec 2011: I have added the classes mentioned here to an open source repo on GitHub. You can find it at <a href="https://github.com/theMikeSwan/TMSSupportClasses" title="TMSSupportClasses">https://github.com/theMikeSwan/TMSSupportClasses</a>. There is also a class to help with implementing iCloud for Mac OS X. Over time I will be adding more support classes and I will add blog posts for them at <a href="http://www.theMikeSwan.com/blog" title="theMikeSwan.com/blog">http://www.theMikeSwan.com/blog</a>.</p>
<div id="_mcePaste">At some point along the line there is still a good chance the user is going to want to print data from our application, either to paper or to a PDF document. So, today we will be talking about just that, printing.</div>
<div id="_mcePaste">As before here is a link to the project as we left it at the end of our last edition.</div>
<div id="_mcePaste"><a href="http://dl.dropbox.com/u/130983/Expenses4.zip">Expenses4.zip</a></div>
<h3 style="text-align:center;"><strong>NSTableView and Printing</strong></h3>
<div id="_mcePaste">You can, if you want just print the NSTableView that has all the expenses in it and call it done. However, as you can see below things may not work how you expect them to.</div>
<div id="_mcePaste"><a href="http://themikeswan.files.wordpress.com/2010/08/preview.png"><img class="aligncenter size-full wp-image-88" title="Top of printed NSTableView" src="http://themikeswan.files.wordpress.com/2010/08/preview.png?w=450&#038;h=60" alt="" width="450" height="60" /></a></div>
<div><a href="http://themikeswan.files.wordpress.com/2010/08/preview-2.png"><img class="aligncenter size-full wp-image-89" title="second page of printed NSTableView" src="http://themikeswan.files.wordpress.com/2010/08/preview-2.png?w=450&#038;h=51" alt="" width="450" height="51" /></a></div>
<div>The first image is of the top of the first page. You may have noticed that there are no headers for the table, in our case it doesn’t really affect us that much since each column is pretty obvious. The first row is also a different color from any of the other rows, because it is selected still. Also, the arrows are still visible on the last row for the popup menus.</div>
<div id="_mcePaste">In the second image you can see that the page break is in the middle of a row, this is something we really need to find a way around.</div>
<div id="_mcePaste">All of these issues stem from the fact that NSTableView isn’t really meant to be printed to paper, it is designed to be drawn on screen only. We could dive into the inner workings of how NSTableView draws itself and make a custom subclass that would look at the drawing context to see if we were drawing to screen or page to work around these problems. We could also follow the common suggestion of using WebKit to basically make a webpage that we print. WebKit does has the advantage of being able to use CSS to style the print (you could even let the user make custom CSS themes). You do of course have to drag WebKit into the mix and write HTML on the fly to dump into a web view, but it’s not really a bad option if you want to go that way.</div>
<div id="_mcePaste">The third option, and the one we will be using today, is to use the wonderful NSTextTable class. NSTextTable has been around since Mac OS X 10.4 so anyone that is actually going to buy your application should meet the minimum system requirements.</div>
<h3 style="text-align:center;"><strong>What is NSTextTable</strong></h3>
<div id="_mcePaste">NSTablePrint is a table made of text, much like tables in HTML. You create a table and set some basic info like how many columns it will have, if borders collapse, etc. Then you build an NSTextTableBlock for each cell in the table adding it to the correct row and column number. You can even tell a block to span multiple rows or columns if you want. The best part is that this table just goes into a regular NSTextView if you want it on screen (it can even be part of a much larger layout with regular text paragraphs and the like). The most tedious part of using NSTextTable is building all of those cells&#8230;</div>
<h3 style="text-align:center;"><strong>MSTablePrint</strong></h3>
<div id="_mcePaste">Since building NSTextTableBlocks is the most tedious part of using NSTextTable I abstracted it out into it’s own class, MSTablePrint. Because I love all of you so much I’m giving that class to you as open source! You do still have to do a little work to use this class as it needs an array of arrays of strings (don’t worry if that doesn’t really make sense yet, it will). MSTablePrint will take that array and return an NSAttributedString with an NSTextTable in it filled with your data. MSTablePrint also allows you to do things like specify a header row and/or column (with their own color, font, etc), specify the general cell format (color, font, etc), and if you want to use alternating rows. You can check out the read me file included with the class for more information. Since we will be using MSTablePrint for this project you should download it now:</div>
<div id="_mcePaste"><a href="http://dl.dropbox.com/u/130983/MSTablePrint.zip">MSTablePrint.zip</a></div>
<div>Once you have the zip file downloaded open it up and drag the .h and .m file to your project to add them.</div>
<h3 style="text-align:center;"><strong>Getting Ink on the Page</strong></h3>
<div id="_mcePaste">Now that we have MSTablePrint added to our project we should use it to actually print something out. The first thing we need to do is add a method declaration to MyDocument.h :</div>
<div id="_mcePaste"><pre class="brush: objc;">
- (NSArray *)rowArrayForItem:(Expense *)item;
</pre></p>
</div>
<div id="_mcePaste">Next we need to import MSTablePrint in MyDocument.m. After that we need to implement both printOperationWithSettings: error: and rowArrayForItem:. We will start with rowArrayForItem: that will give us an array of strings formatted the way we want them to look when printed:</div>
<div><pre class="brush: objc; wrap-lines: false;">
 (NSArray *)rowArrayForItem:(Expense *)item {
    // This method is only available in 10.6 and later for 10.5 follow the commented code below.
    NSString *dateString = [NSDateFormatter localizedStringFromDate:item.date dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterNoStyle];
    /*
        NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
        [dateFormatter setDateStyle:dateStyle];
        [dateFormatter setTimeStyle:timeStyle];
        NSString *dateString = [dateFormatter stringForObjectValue:item.date];
    */
    // This method is also only available in 10.6 and later, for 10.5 refer to the code above for the date formatter making subistutions as needed.
    NSString *amountString = [NSNumberFormatter localizedStringFromNumber:item.amount numberStyle:NSNumberFormatterCurrencyStyle];
    NSString *descriptionString = item.desc;
    NSString *categoryString = item.category.name;
    return [NSArray arrayWithObjects:dateString, amountString, descriptionString, categoryString, nil]; // The order here will match the order in the text table
}
</pre></p>
<div id="_mcePaste">Now for printOperationWithSettings: error: this is called automatically to the front document by the system when the user selects Print&#8230; from the File menu:</div>
<div><pre class="brush: objc; wrap-lines: false;">
- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings error:(NSError **)outError {
    NSPrintInfo *pInfo = [self printInfo];
    [pInfo setHorizontalPagination:NSFitPagination]; // This will keep the text table from spanning more than one page across.
    [pInfo setVerticallyCentered:NO]; // Keep the table from ending up in the middle of the page. Not that big of a deal for one page, but the last page looks odd without this.
    [[pInfo dictionary] setValue:[NSNumber numberWithBool:YES] forKey:NSPrintHeaderAndFooter]; // Add header and footer to all pages
    [[pInfo dictionary] addEntriesFromDictionary:printSettings]; // Add any settings that were passed in.
    NSTextView *printView = [[[NSTextView alloc] initWithFrame:[pInfo imageablePageBounds]] autorelease]; // Create a text view with one page as its size
    printView.jobTitle = @&amp;quot;Expense Report&amp;quot;; // The name used as default for save as PDF and for the default header
    MSTablePrint *tPrint = [[[MSTablePrint alloc] init] autorelease];
    // Set up the fetch request to retrive all Expense entities
    NSEntityDescription *entity = [NSEntityDescription entityForName:@&amp;quot;Expense&amp;quot; inManagedObjectContext:[self managedObjectContext]];
    NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
    [request setEntity:entity];
    NSError *anError = nil;
    NSArray *items = [[self managedObjectContext] executeFetchRequest:request error:&amp;amp;anError];
    NSArray *headerArray = [NSArray arrayWithObjects:@&amp;quot;Date&amp;quot;, @&amp;quot;Amount&amp;quot;, @&amp;quot;Description&amp;quot;, @&amp;quot;Category&amp;quot;, nil]; // create the first row of the text table with headers
    NSMutableArray *itemArray = [[[NSMutableArray alloc] init] autorelease]; // create the array we will be passing to MSTablePrint
    [itemArray addObject:headerArray]; // whatever is at index 0 of this array will become the first row so we add the headers here
    for (Expense *z in items) { // Step through each Expense entity in the array and create an array to represent the entity.
        [itemArray addObject:[self rowArrayForItem:z]];
    }
    NSAttributedString *atString = [tPrint attributedStringFromItems:itemArray]; //create the text table
    [[printView textStorage] setAttributedString:atString]; // set the text table as the only text in the text view
     NSPrintOperation *printOp = [NSPrintOperation printOperationWithView:printView printInfo:pInfo]; // Setup the actual print operation
     return printOp;
}
</pre></p>
</div>
<div id="_mcePaste">You can, of course, leave out the comments as they are really just to explain what each line is doing.</div>
<div id="_mcePaste">Now if you Build and Go you can print whatever document you want. Try adding lots of entries to a document and you will see that page breaks go around rows, not through them. You can do all the extra customizations you want to the text table before you actually create the string if you want things like red text, or a particular font.</div>
<h3 style="text-align:center;"><strong>Headers and Footers</strong></h3>
<div id="_mcePaste">Adding the default header and footer is super easy to do. All we have to do is add one line of code to printOperationWithSettings: error: that will tell the system to add a header and footer to all pages for us:</div>
<p><pre class="brush: objc; wrap-lines: false;">

    [[pInfo dictionary] setValue:[NSNumber numberWithBool:YES] forKey:NSPrintHeaderAndFooter];
</pre></p>
</div>
<div>Now if we Build and Run then select Print we will see in the preview that there is a header that says ‘Untitled’ on the left and has the date and time on the right. On the bottom right is the page number and total page count. This is a perfectly fine header for most things except part that says ‘Untitled’ we should do something about that.</div>
<div id="_mcePaste">Adding a more descriptive title to the header will take a little more work since our text view doesn’t have a window for the system to pull the title from. NSView has a method  printJobTitle that tells the system what to use in the header and as the default file name for saving as a PDF file. This method normally looks for things like the window title, however our text view is not part of a window so this method just returns ‘Untitled’. Currently NSView does not have a setter for printJobTitle so we will have to subclass NSTextView and add one ourselves.</div>
<div id="_mcePaste">Go ahead and create a new Objective-C subclass of NSObject and call it PrintTextView. In PrintTextView.h add:</div>
<div><pre class="brush: objc; wrap-lines: false;">
@interface PrintTextView : NSTextView {
    NSString *printJobTitle;
}
@property (copy, readwrite) NSString *printJobTitle;
@end
</pre></p>
</div>
<div>In PrintTextView.m we just need to synthesize printJobTitle and of course release it in dealloc so this is all we need to add:</div>
<div><pre class="brush: objc; wrap-lines: false;">
@implementation PrintTextView
@synthesize printJobTitle;
- (void)dealloc {
    // Clean-up code here.
    [printJobTitle release];
    self.printJobTitle = nil;
    [super dealloc];
}
@end
</pre></p>
</div>
<div id="_mcePaste">Now that we have our new subclass of NSTextView we just need to make a couple changes in MyDocument.m to use it. First off, we need to import PrintTextView.h so the complier doesn’t get upset. Then, in printOperationWithSettings: error:, we need to change one line of code and add one line.</div>
<div id="_mcePaste">Change:</div>
<div><pre class="brush: objc; wrap-lines: false;">
     PrintTextView *printView = [[[PrintTextView alloc] initWithFrame:[pInfo imageablePageBounds]] autorelease]; // Create a text view with one page as its size
</pre></p>
</div>
<div id="_mcePaste">Add:</div>
<div><pre class="brush: objc;">
     printView.printJobTitle = @&amp;quot;Expense Report&amp;quot;;
</pre></p>
</div>
<div id="_mcePaste">You can, of course, set printJobTitle to whatever string you want, perhaps pull the name of the document and use that [self displayName], but since the print out really is an expense report why not call it one.</div>
<div id="_mcePaste">Now if you build and run you will see that ‘Untitled’ has changed to ‘Expense Report.’</div>
<h3 style="text-align:center;"><strong>That’s all folks</strong></h3>
<div id="_mcePaste">That brings us to the end of our time together today. I’ don’t know when I will have the next installment out for you, or even what it will cover, if you have any topics you would like to see covered here please let me know in the comments.</div>
<div id="_mcePaste">If for some reason something isn’t working for you at this point here is a zip file of the project at this point, along with a sample file:</div>
<div id="_mcePaste"><a href="http://dl.dropbox.com/u/130983/Expenses5.zip">Expenses5.zip</a></div>
<div id="_mcePaste">As always, I look forward to your comments, questions, complaints, suggestions, etc.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=86&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2010/08/05/expenses-part-5-printing-core-data/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/08/preview.png" medium="image">
			<media:title type="html">Top of printed NSTableView</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/08/preview-2.png" medium="image">
			<media:title type="html">second page of printed NSTableView</media:title>
		</media:content>
	</item>
		<item>
		<title>Printing Tabular Data</title>
		<link>http://themikeswan.wordpress.com/2010/07/31/printing-tabular-data/</link>
		<comments>http://themikeswan.wordpress.com/2010/07/31/printing-tabular-data/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 08:40:50 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Core Data]]></category>
		<category><![CDATA[Source Code]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/?p=82</guid>
		<description><![CDATA[So I have been working on a Core Data application for Mac OS X that will eventually have an iPhone and iPad. I have been learning how to write software in general and Cocoa code specifically along the way. A few days ago I started working on printing so I did what I always do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=82&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I have been working on a Core Data application for Mac OS X that will eventually have an iPhone and iPad. I have been learning how to write software in general and Cocoa code specifically along the way. A few days ago I started working on printing so I did what I always do when I need to learn a new piece and Google it. I found that there was very little out there on the subject, further what was there was fairly vague and mostly boiled down to &#8216;use WebKit and print that.&#8217; I eventually found a little info that lead me to NSTextTable. Since I foresee making several applications that will need similar printing I decided to abstract as much code as possible out into it&#8217;s own class. My goal was to have a class that I could just hand over an array of objects (Core Data or not) and get a table back. I quickly discovered that I would have to send so much information to the class that it would be ridiculous, so I changed to an idea that just used strings.<br />
I ended up with a class that I just had to create an array of arrays of strings to get an attributed string with a text table in it.<br />
Since there is no little out on the web on this subject and I have gotten so much help from the web on some many other subjects I have decided to put my new class MSTablePrint out in to the world for anyone to use. I have given it the same license the Matt Gemmell uses for his source code (I literally copied it from his site and swapped out my name for his). This means that you are free to use this code in any project you want so long as you acknowledge my contribution. If you want for of a description just check out http://mattgemmell.com/license/ (Since I &#8216;borrowed&#8217; the license from Mr. Gemmell I might as well link to his explanation (also feel free to check out the rest of his site while you&#8217;re there, he is _way_ smarter than me with this stuff).</p>
<p>To use this class you need to grab whatever objects you want in your table. Then create an array of strings from the keys you are interested in, in the order you want them to appear (the string at index 0 will end up in the first column). Once the strings are in an array add that array to another array. Whatever array is at index 0 will become the first row so if you want headers you should make them the first array. There are numerous other options you can set such as alternating row colors and header row styles that are all covered in the read me file in the zip file.</p>
<p>I will likely put up a tutorial in a few days using the Expenses application, but in the mean time feel free to post questions here so others can share in the answers.</p>
<p><a href="http://dl.dropbox.com/u/130983/MSTablePrint.zip" target="_blank">MSTablePrint</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/82/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=82&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2010/07/31/printing-tabular-data/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>
	</item>
		<item>
		<title>WWDC 2010 Session Breakdown</title>
		<link>http://themikeswan.wordpress.com/2010/04/28/wwdc-2010-session-breakdown/</link>
		<comments>http://themikeswan.wordpress.com/2010/04/28/wwdc-2010-session-breakdown/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 18:16:02 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/?p=73</guid>
		<description><![CDATA[So the information for WWDC came out today (with a whopping 5 weeks notice) and it struck me, as it has many people judging by Twitter, that this year Mac OS X is the red headed step child more so than ever. To demonstrate this I went through all the sessions, of which there are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=73&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So the information for WWDC came out today (with a whopping 5 weeks notice) and it struck me, as it has many people judging by Twitter, that this year Mac OS X is the red headed step child more so than ever. To demonstrate this I went through all the sessions, of which there are 66 this year, and determined if they were just for iPhone OS, just for Mac OS X, for both, or weren&#8217;t really specified. I did this overall and by category and here are the resulting charts:</p>
<p><a href="http://themikeswan.files.wordpress.com/2010/04/numbers-6.png"><img class="aligncenter size-full wp-image-74" title="Overall" src="http://themikeswan.files.wordpress.com/2010/04/numbers-6.png?w=450" alt=""   /></a><a href="http://themikeswan.files.wordpress.com/2010/04/numbers-4.png"><img class="aligncenter size-full wp-image-77" title="Application Frameworks" src="http://themikeswan.files.wordpress.com/2010/04/numbers-4.png?w=450" alt=""   /></a><a href="http://themikeswan.files.wordpress.com/2010/04/numbers-5.png"><img class="aligncenter size-full wp-image-78" title="Core OS" src="http://themikeswan.files.wordpress.com/2010/04/numbers-5.png?w=450" alt=""   /></a><a href="http://themikeswan.files.wordpress.com/2010/04/numbers-3.png"><img class="aligncenter size-full wp-image-76" title="Developer Tools" src="http://themikeswan.files.wordpress.com/2010/04/numbers-3.png?w=450" alt=""   /></a><a href="http://themikeswan.files.wordpress.com/2010/04/numbers-2.png"><img class="aligncenter size-full wp-image-75" title="Graphics and media" src="http://themikeswan.files.wordpress.com/2010/04/numbers-2.png?w=450" alt=""   /></a><a href="http://themikeswan.files.wordpress.com/2010/04/numbers.png"><img class="aligncenter size-full wp-image-79" title="Internet &amp; Web" src="http://themikeswan.files.wordpress.com/2010/04/numbers.png?w=450" alt=""   /></a>As you can see almost every session applies to iPhone OS in some way and very few apply to only Mac OS X. If this is any indication then even the sessions that apply to both OSes will mostly focus on iPhone OS. The question now is, is it really worth it for non-iPhone developers to bother going this year?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=73&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2010/04/28/wwdc-2010-session-breakdown/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/04/numbers-6.png" medium="image">
			<media:title type="html">Overall</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/04/numbers-4.png" medium="image">
			<media:title type="html">Application Frameworks</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/04/numbers-5.png" medium="image">
			<media:title type="html">Core OS</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/04/numbers-3.png" medium="image">
			<media:title type="html">Developer Tools</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/04/numbers-2.png" medium="image">
			<media:title type="html">Graphics and media</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/04/numbers.png" medium="image">
			<media:title type="html">Internet &#38; Web</media:title>
		</media:content>
	</item>
		<item>
		<title>Troubleshooting tips part 1: NSLog, etc.</title>
		<link>http://themikeswan.wordpress.com/2010/01/31/troubleshooting-tips-part-1-nslog-etc/</link>
		<comments>http://themikeswan.wordpress.com/2010/01/31/troubleshooting-tips-part-1-nslog-etc/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 00:28:14 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/2010/01/31/troubleshooting-tips-part-1-nslog-etc/</guid>
		<description><![CDATA[In the course of working on part four of the Expenses tutorial I kept getting the error about the store being incompatible with the store used to create the file despite the fact that I copied the code over from a working project. I of course started with the generic “Clean All” option, but that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=72&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the course of working on part four of the Expenses tutorial I kept getting the error about the store being incompatible with the store used to create the file despite the fact that I copied the code over from a working project. I of course started with the generic “Clean All” option, but that didn’t do me any good. As I have never had any formal programming classes (other than a year in Middle school where we had to make a flowchart for how to make a cheeseburger and wrote everything in BASIC, and I don’t mean Visual Basic, I mean late 1980’s BASIC) I don’t really understand how debuggers work, I can do some really basic stuff with the Xcode one now, but nothing of substance. After I was convinced that I had done everything right (after all I’m perfect, right?) I added a single NSLog to the start of the newly overridden method NSLog(@&#8221;configuring store.&#8221;);. Then I hit build and run, and was confronted by the lack of any statements in the log about configuring store. I was of course at once convinced that there must be something wrong in the system so I, again, did the default “Clean” thinking that would solve it, still no message in the log. I tried a different machine, still no log message. I then went hunting in the docs to see if the method had been deprecated, but it hadn’t been. In desperation I copied the method from the documentation and pasted it into my code, suddenly I had a log message and it all worked. I, of course, was confused and so looked back through the part of the tutorial with the method in it, to see if I miss a part of the method or something. It looked right&#8230; until I finally looked letter by letter and saw that I had mis-spelled coordinator by leaving out an ‘o’ the odds of me mis-spelling words is pretty high (I suck at spelling) so I should have looked for that kind of thing sooner, but I thought I had pulled from working code.<br />
As I have been learning to write software these kinds of things have happened less often, somewhat due to experience but mostly because I have learned ways to work with my ignorance.I use NSLog all over the place to help find where things go off the tracks. I have logged each step of a method that was giving me issues before, putting in the values of variables and counts of arrays to see if what I designed to have happen actually happens. This of course means that I have to get rid of all those NSLogs at some point, or have my customer’s console fill up with crap every time they run my app (assuming, of course that I will have more than just the one small Mac app and two small iPhone apps out one day). There are several approaches out there to making this easy, I tend to go really low tech and just #define MSLOG to be either ‘NSLog’ or ‘//’ Depending on what kind of build I am doing. I haven’t used much in the way of automated defines or used scripts in my build process as of yet, but I am now starting to learn such things. So far I have a simple script that increments the build number each time (I got the basic script from a blog whose name now escapes me and altered it to work the way I wanted).<br />
One of the other things I have started doing is keeping a notes file in each project so I can keep track of things right in the project. I am now starting to work on a way to split this notes file out of the app but in the same folder. The idea behind the notes file is that I put in more info than would normally go into a commit message, while the commit message might say something like adds feature x, the notes file will say how feature x was added so I can do it again in a different project if I want. THe notes file also gives me a place to record ideas that didn’t work so I don’t try to get a feature to work the same wrong way five different times. This is really useful for me since I tend to have multiple projects of similar idea at the same time and may go months between times I work on one of them, generally I have one that is my real project and one that is my sandbox to try ideas out. Once I get an idea to work in the sandbox I move it over to the main project using the notes file as a guide for what I need to copy and paste over and what IB connections and bindings are needed.<br />
Let me know what you all have come up with to make your coding lives easier. As I come up with other ideas, possibly based on some of your comments, I will post about them as well.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=72&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2010/01/31/troubleshooting-tips-part-1-nslog-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>
	</item>
		<item>
		<title>Expenses: A Core Data Tutorial Part 4, Versioning</title>
		<link>http://themikeswan.wordpress.com/2010/01/27/expenses-a-core-data-tutorial-part-4-versioning/</link>
		<comments>http://themikeswan.wordpress.com/2010/01/27/expenses-a-core-data-tutorial-part-4-versioning/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 02:11:41 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Core Data]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/?p=62</guid>
		<description><![CDATA[Basic Data Versioning This time we are going to be working with some basic data migration. In OS X 10.4 &#38; 10.5 data migration was a bit tricky (mostly because the Apple docs weren’t very clear about a method you had to add to make all the pieces work). OS X 10.6 has made things [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=62&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Basic Data Versioning</strong></p>
<p>This time we are going to be working with some basic data migration. In OS X 10.4 &amp; 10.5 data migration was a bit tricky (mostly because the Apple docs weren’t very clear about a method you had to add to make all the pieces work). OS X 10.6 has made things a bit easier. We will cover the differences when we get there.</p>
<p>As before here is a link to the project as we left it at the end of our last edition.</p>
<p><a href="http://dl.dropbox.com/u/130983/Expenses3.zip" target="_blank">Expenses3.zip</a></p>
<p><strong>Creating the new model</strong></p>
<p>To start with we need to create a new data model file. Select the current data model, then select Design -&gt; Data Model -&gt; Add Model Version.</p>
<p><a href="http://themikeswan.files.wordpress.com/2010/01/addmodelversion.png"><img class="aligncenter size-medium wp-image-63" title="addModelVersion" src="http://themikeswan.files.wordpress.com/2010/01/addmodelversion.png?w=300&#038;h=151" alt="Add Model Version" width="300" height="151" /></a></p>
<p>This will create a copy of the data model file named “MyDocument 2.xcdatamodel.” if you look you will also notice that in the Groups &amp; Files list there has been a change where the original file was, it now has a disclosure triangle and a new extension “.xcdatamodeld” this is the directory that all the versions of the model file will go. The original file also has a green check mark on it’s icon now to indicate that it is the current version of the data model. You can either edit the original or duplicate file, both will work. I prefer to edit the duplicate file so I can keep track of things. Select the new model file then Design -&gt; Data Model -&gt;Set Current Version. For this project just add an attribute named “notes” to the Expenses entity with a type of string.</p>
<p><a href="http://themikeswan.files.wordpress.com/2010/01/newattribute.png"><img class="aligncenter size-medium wp-image-64" title="newAttribute" src="http://themikeswan.files.wordpress.com/2010/01/newattribute.png?w=300&#038;h=186" alt="Adding Notes Attribute" width="300" height="186" /></a></p>
<p>Save the new model file. To see why I always edit the duplicate file select the data model and create another new version, you will see that it is number 3 and is a copy of version 2. All the versions of the model file are sorted in order so it is very easy to see which one is the newest one. Of course for a commercial app you may want to name data models based on the app version so you know what version has what data model for support and the such. You can delete version 3 of the model file as we won’t be using it.</p>
<p><strong>GUI Changes</strong></p>
<p>In order to actually use our new notes attribute we need to make some changes to the GUI. First, open MyDocument.xib and select the Expenses tab. lengthen the window, tab view, and box to allow for the addition of an NSTextView. Drag over an NSTextView sizing it as needed. Click on the text view as needed to actually get the NSTextView selected. In the inspector turn off rich text and then bind the Value to: ExpenseView Array Controller.selection.notes. You could just save and close at this point, but first look at the Categories tab. Lots of dead space down there, perhaps we should do something about that. For a simple fix just lengthen the two table views, moving things down as needed, to take up the extra space. Now, save and close.</p>
<p><a href="http://themikeswan.files.wordpress.com/2010/01/newgui.png"><img class="aligncenter size-medium wp-image-65" title="newGUI" src="http://themikeswan.files.wordpress.com/2010/01/newgui.png?w=300&#038;h=243" alt="The New GUI" width="300" height="243" /></a></p>
<p><strong>Turning on Migration</strong></p>
<p>The thing that the Apple documentation was always a little lacking on in OS X 10.4 &amp; 10.5 was actually turning on the migration, It took me forever the first time I tried to do any migration to actually make things work before I found this little tidbit. We have to override  &#8211; (BOOL) configurePersistentStoreCoordinatorForURL: (NSURL *)url ofType: (NSString *) fileType modelConfiguration: (NSString *) configuration storeOptions: (NSDictionary *) storeOptions error: (NSError **)error in MyDocument.m to let the system know it should migrate the data. Here is where things diverge a bit for OS X 10.4 &amp; 10.5 versus 10.6. For the older versions we use the following code along with a mapping model, which we will cover in a moment.:</p>
<p>- (BOOL) configurePersistentStoreCoordinatorForURL: (NSURL *)url ofType: (NSString *) fileType modelConfiguration: (NSString *) configuration storeOptions: (NSDictionary *) storeOptions error: (NSError **)error</p>
<p>{</p>
<p>NSMutableDictionary *options = nil;</p>
<p>if (storeOptions != nil)</p>
<p>{</p>
<p>options = [storeOptions mutableCopy];</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>options = [[NSMutableDictionary alloc] init];</p>
<p>}</p>
<p>[options setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];</p>
<p>BOOL result = [super configurePersistentStoreCoordinatorForURL:url ofType:fileType modelConfiguration:configuration storeOptions:options error:error];</p>
<p>[options release], options = nil;</p>
<p>return result;</p>
<p>}</p>
<p>With a migration this simple, just adding an attribute to an entity, in Snow Leopard we use code that looks just like above with just the addition of a second key in the dictionary set to yes that will save us making a mapping model.:</p>
<p>- (BOOL) configurePersistentStoreCoordinatorForURL: (NSURL *)url ofType: (NSString *) fileType modelConfiguration: (NSString *) configuration storeOptions: (NSDictionary *) storeOptions error: (NSError **)error</p>
<p>{</p>
<p>NSMutableDictionary *options = nil;</p>
<p>if (storeOptions != nil)</p>
<p>{</p>
<p>options = [storeOptions mutableCopy];</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>options = [[NSMutableDictionary alloc] init];</p>
<p>}</p>
<p>[options setObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];</p>
<p>// Add this line for simple migrations in Snow Leopard</p>
<p>[options setObject:[NSNumber numberWithBool:YES] forKey: NSInferMappingModelAutomaticallyOption];</p>
<p>BOOL result = [super configurePersistentStoreCoordinatorForURL:url ofType:fileType modelConfiguration:configuration storeOptions:options error:error];</p>
<p>[options release], options = nil;</p>
<p>return result;</p>
<p>}</p>
<p><strong>Mapping Model</strong></p>
<p>A mapping model tells the system how to get from one version of a data model to the other. For basic migrations we only need a mapping model for OS X 10.4 &amp; 10.5, for more advanced migrations we need a mapping model under OS X 10.6 as well. For this project the mapping model will be very basic. We start by creating a new mapping model file (File-&gt; New File…), this changed from OS X 10.5 to 10.6 so both views are shown: (Note that if you aren’t presented with the mapping model option cancel, select the data model and try again.)</p>
<p><a href="http://themikeswan.files.wordpress.com/2010/01/mappingmodel.png"><img class="aligncenter size-medium wp-image-66" title="mappingModel" src="http://themikeswan.files.wordpress.com/2010/01/mappingmodel.png?w=300&#038;h=220" alt="Mapping Model in 10.5" width="300" height="220" /></a></p>
<p>OS X 10.5</p>
<p><a href="http://themikeswan.files.wordpress.com/2010/01/new-file.png"><img class="aligncenter size-medium wp-image-67" title="New File" src="http://themikeswan.files.wordpress.com/2010/01/new-file.png?w=300&#038;h=230" alt="Mapping Model in 10.6" width="300" height="230" /></a></p>
<p>OS X 10.6</p>
<p>I named mine “ver1to2” but the name is fairly unimportant. After you name the file you will be asked for the source and destination files. Select the original model for the source and the new model for the destination.</p>
<p><a href="http://themikeswan.files.wordpress.com/2010/01/mapsourceanddest.png"><img class="aligncenter size-medium wp-image-68" title="mapSourceAndDest" src="http://themikeswan.files.wordpress.com/2010/01/mapsourceanddest.png?w=300&#038;h=220" alt="Source and destination for the mapping Model" width="300" height="220" /></a></p>
<p>Since all we did was add one attribute the default mapping model will suffice. Xcode will look at both models and see that there is only one additional attribute and map all the pre-existing entities and attributes to the proper destinations. If you wanted to fill the notes attribute with some sort of migrated from old store message you could do it in this file.</p>
<p>If you hadn’t overridden &#8211; (BOOL) configurePersistentStoreCoordinatorForURL: (NSURL *)url ofType: (NSString *) fileType modelConfiguration: (NSString *) configuration storeOptions: (NSDictionary *) storeOptions error: (NSError **)error you would get something like this (I got this a lot the first time I tried to do migration):</p>
<p><a href="http://themikeswan.files.wordpress.com/2010/01/versioningerror.png"><img class="aligncenter size-medium wp-image-69" title="versioningError" src="http://themikeswan.files.wordpress.com/2010/01/versioningerror.png?w=300&#038;h=140" alt="" width="300" height="140" /></a></p>
<p>Of course you have overridden that method so you won’t have that problem.</p>
<p><strong>That’s all folks</strong></p>
<p>That brings us to the end of our time together today. I’m pondering what we should do in the next edition, but hopefully it will be something interesting. If for some reason something isn’t working for you at this point here is a zip file of the project at this point, along with a sample file:</p>
<p><a href="http://dl.dropbox.com/u/130983/Expenses4.zip" target="_blank">Expenses4.zip</a></p>
<p>As always, I look forward to your comments, questions, complaints, suggestions, etc.</p>
<div><span style="font-family:Helvetica, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size:small;"><br />
</span></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=62&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2010/01/27/expenses-a-core-data-tutorial-part-4-versioning/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/01/addmodelversion.png?w=300" medium="image">
			<media:title type="html">addModelVersion</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/01/newattribute.png?w=300" medium="image">
			<media:title type="html">newAttribute</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/01/newgui.png?w=300" medium="image">
			<media:title type="html">newGUI</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/01/mappingmodel.png?w=300" medium="image">
			<media:title type="html">mappingModel</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/01/new-file.png?w=300" medium="image">
			<media:title type="html">New File</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/01/mapsourceanddest.png?w=300" medium="image">
			<media:title type="html">mapSourceAndDest</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2010/01/versioningerror.png?w=300" medium="image">
			<media:title type="html">versioningError</media:title>
		</media:content>
	</item>
		<item>
		<title>Expenses: A Core Data Tutorial part 3</title>
		<link>http://themikeswan.wordpress.com/2009/06/23/expenses-a-core-data-tutorial-part-3/</link>
		<comments>http://themikeswan.wordpress.com/2009/06/23/expenses-a-core-data-tutorial-part-3/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 01:16:46 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Core Data]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/?p=56</guid>
		<description><![CDATA[User Preferences So it has taken far longer than I anticipated to get this one out, but I suppose these things happen. This time we will be setting up some user defaults, we will be doing far less with Core Data specific stuff but a lot of this stills ties into Core Data. Preferences we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=56&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1 style="text-align:center;"><strong>User Preferences</strong></h1>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">So it has taken far longer than I anticipated to get this one out, but I suppose these things happen. This time we will be setting up some user defaults, we will be doing far less with Core Data specific stuff but a lot of this stills ties into Core Data.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Preferences we will add:</span></p>
<ul>
<li><span style="letter-spacing:0;">When we launch should we open a blank document, nothing, or the last edited document.</span></li>
<li><span style="letter-spacing:0;">How far from the current date should expenses default to.</span></li>
<li><span style="letter-spacing:0;">Are there any categories the user would like added to all new documents.</span></li>
</ul>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">If you skipped the first two tutorials and would rather not do them here is a link to the project as of the end of part 2.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong><a href="http://files.getdropbox.com/u/130983/ExpensesPart2.zip" target="_blank">Expenses Part 2</a></strong></span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">We will be making a few new files today, if you want to create them all at once here is the list:</span></p>
<ul>
<li><span style="letter-spacing:0;">externs.h (Empty File)</span></li>
<li><span style="letter-spacing:0;">AppController.h &amp;.m (Objective-C class)</span></li>
<li><span style="letter-spacing:0;">PreferenceController.h &amp; .m (Objective-C NSWindowController subclass)</span></li>
<li><span style="letter-spacing:0;">Preference.xib (Window XIB)</span></li>
</ul>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">I am not going to go into huge detail about how NSUserDefaults works since numerous others have done an excellent job, including my two favorite places, CocoaDevCentral and Aaron’s book, </span><span style="font:11px Lucida Grande;text-decoration:underline;letter-spacing:0;"><a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2Fs%3Fie%3DUTF8%26keywords%3D9780321503619%26index%3Dblended&amp;tag=micsswaligtec-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=390957" target="_blank">Cocoa Programming for Mac OS X</a></span><span style="letter-spacing:0;">. We are going to go a bit beyond what is currently covered in either of those places though.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>The externs file</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">So whenever I am going to have lots of externs I like to put them all in one file so they are easy to find when I forget what they are called. Then I just have to import them into each class file to use them. We will define several externs that will be the keys to our user defaults dictionary. </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Create a new file that is a blank file, and name it “externs.h” then make it look like this:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;">/*</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>externs.h</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>This is just a collection of all externs for the project.</span></p>
<p style="font:10px Monaco;color:#007400;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;"> */</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;">// To determine if we should oopen a blank document at launch</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0 color;">extern</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> * </span><span style="letter-spacing:0 color;">const</span><span style="letter-spacing:0;"> ExpEmptyDocKey;</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;">// To determine if we should open the last opened document at launch</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0 color;">extern</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> * </span><span style="letter-spacing:0 color;">const</span><span style="letter-spacing:0;"> ExpOpenLastDocKey;</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;">// To determine if we should insert the default categories to new docs</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0 color;">extern</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> * </span><span style="letter-spacing:0 color;">const</span><span style="letter-spacing:0;"> ExpDefaultCategoriesKey;</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;">// The list of what categories should get added if above is YES</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0 color;">extern</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> * </span><span style="letter-spacing:0 color;">const</span><span style="letter-spacing:0;"> ExpDefaultCategoriesList;</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;">// How far before the current date should expenses start at.</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0 color;">extern</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> * </span><span style="letter-spacing:0 color;">const</span><span style="letter-spacing:0;"> ExpDefaultDateOffset;</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Don’t forget to save!</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>AppController part 1</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Now we need to set the ‘factory’ defaults. To do this we need to edit the AppController class a bit. If you have not already created the files do so now. Then, in AppController.h add the following above </span><span style="font:10px Monaco;letter-spacing:0 color;">@interface</span><span style="letter-spacing:0;"> :</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="color:#000000;">#import </span><span style="letter-spacing:0;"><span style="color:#000000;">&#8220;Externs.h&#8221;</span></span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="color:#000000;"> </span></span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="color:#000000;">NSString</span><span style="color:#000000;"> * </span><span style="color:#000000;">const</span><span style="color:#000000;"> </span><span style="color:#000000;">ExpEmptyDocKey</span><span style="color:#000000;"> = </span><span style="letter-spacing:0;"><span style="color:#000000;">@&#8221;EmptyDocumentFlag&#8221;</span></span><span style="color:#000000;">;</span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="color:#000000;">NSString</span><span style="color:#000000;"> * </span><span style="color:#000000;">const</span><span style="color:#000000;"> </span><span style="color:#000000;">ExpOpenLastDocKey</span><span style="color:#000000;"> = </span><span style="letter-spacing:0;"><span style="color:#000000;">@&#8221;OpenLastDocFLag&#8221;</span></span><span style="color:#000000;">;</span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="color:#000000;">NSString</span><span style="color:#000000;"> * </span><span style="color:#000000;">const</span><span style="color:#000000;"> </span><span style="color:#000000;">ExpDefaultCategoriesKey</span><span style="color:#000000;"> = </span><span style="letter-spacing:0;"><span style="color:#000000;">@&#8221;DefaultCategoriesFlag&#8221;</span></span><span style="color:#000000;">;</span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="color:#000000;">NSString</span><span style="color:#000000;"> * </span><span style="color:#000000;">const</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">ExpDefaultCategoriesList</span></span><span style="color:#000000;"> = </span><span style="color:#000000;">@&#8221;DefaultCategoriesList&#8221;</span><span style="color:#000000;">;</span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="color:#000000;">NSString</span><span style="color:#000000;"> * </span><span style="color:#000000;">const</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">ExpDefaultDateOffset</span></span><span style="color:#000000;"> = </span><span style="color:#000000;">@&#8221;DefaultDateOffset&#8221;</span><span style="color:#000000;">;</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">After that, in AppController.m add this code: (I’m not really happy with all of this code, but I haven’t found a better way to deal with the KVC issues in IB without using dictionaries)</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:9px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0;">@implementation</span><span style="letter-spacing:0 color;"> AppController</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">+ (</span><span style="letter-spacing:0 color;">void</span><span style="letter-spacing:0;">) initialize</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// create a dictionary for the &#8216;factory&#8217; defaults</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> *defaultValues = [</span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> </span><span style="color:#000000;">dictionary</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// First to create an array of default Categories (for now we will just make a few)</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> *catOne = [[[</span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> </span><span style="color:#000000;">alloc</span><span style="color:#000000;">] </span><span style="color:#000000;">initWithCapacity</span><span style="color:#000000;">:</span><span style="color:#000000;">1</span><span style="color:#000000;">] </span><span style="color:#000000;">autorelease</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> *catTwo = [[[</span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> </span><span style="color:#000000;">alloc</span><span style="color:#000000;">] </span><span style="color:#000000;">initWithCapacity</span><span style="color:#000000;">:</span><span style="color:#000000;">1</span><span style="color:#000000;">] </span><span style="color:#000000;">autorelease</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> *catThree = [[[</span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> </span><span style="color:#000000;">alloc</span><span style="color:#000000;">] </span><span style="color:#000000;">initWithCapacity</span><span style="color:#000000;">:</span><span style="color:#000000;">1</span><span style="color:#000000;">] </span><span style="color:#000000;">autorelease</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> *catFour = [[[</span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> </span><span style="color:#000000;">alloc</span><span style="color:#000000;">] </span><span style="color:#000000;">initWithCapacity</span><span style="color:#000000;">:</span><span style="color:#000000;">1</span><span style="color:#000000;">] </span><span style="color:#000000;">autorelease</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> *catFive = [[[</span><span style="letter-spacing:0;"><span style="color:#000000;">NSMutableDictionary</span></span><span style="color:#000000;"> </span><span style="color:#000000;">alloc</span><span style="color:#000000;">] </span><span style="color:#000000;">initWithCapacity</span><span style="color:#000000;">:</span><span style="color:#000000;">1</span><span style="color:#000000;">] </span><span style="color:#000000;">autorelease</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[catOne</span><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="color:#000000;">setValue</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"Housing"</span></span><span style="color:#000000;"> </span><span style="color:#000000;">forKey</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"theString"</span></span><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">];</span></span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[catTwo</span><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="color:#000000;">setValue</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"Food"</span></span><span style="color:#000000;"> </span><span style="color:#000000;">forKey</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"theString"</span></span><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">];</span></span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[catThree </span></span><span style="color:#000000;">setValue</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"Entertainment"</span></span><span style="color:#000000;"> </span><span style="color:#000000;">forKey</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"theString"</span></span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[catFour </span></span><span style="color:#000000;">setValue</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"Misc"</span></span><span style="color:#000000;"> </span><span style="color:#000000;">forKey</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"theString"</span></span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[catFive </span></span><span style="color:#000000;">setValue</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"Transportation"</span></span><span style="color:#000000;"> </span><span style="color:#000000;">forKey</span><span style="color:#000000;">:</span><span style="letter-spacing:0;"><span style="color:#000000;">@"theString"</span></span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="color:#000000;">NSArray</span><span style="letter-spacing:0;"><span style="color:#000000;"> *catArray = [</span></span><span style="color:#000000;">NSArray</span><span style="letter-spacing:0;"><span style="color:#000000;"> </span></span><span style="color:#000000;">arrayWithObjects</span><span style="letter-spacing:0;"><span style="color:#000000;">:catOne, catTwo, catThree, catFour, catFive, </span></span><span style="color:#000000;">nil</span><span style="letter-spacing:0;"><span style="color:#000000;">];</span></span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// add defaults to dictionary</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[defaultValues </span></span><span style="letter-spacing:0;"><span style="color:#000000;">setObject</span></span><span style="color:#000000;">:[</span><span style="color:#000000;">NSNumber</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">numberWithBool</span></span><span style="color:#000000;">:</span><span style="color:#000000;">YES</span><span style="color:#000000;">] </span><span style="letter-spacing:0;"><span style="color:#000000;">forKey</span></span><span style="color:#000000;">:</span><span style="color:#000000;">ExpEmptyDocKey</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[defaultValues </span></span><span style="letter-spacing:0;"><span style="color:#000000;">setObject</span></span><span style="color:#000000;">:[</span><span style="color:#000000;">NSNumber</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">numberWithBool</span></span><span style="color:#000000;">:</span><span style="color:#000000;">YES</span><span style="color:#000000;">] </span><span style="letter-spacing:0;"><span style="color:#000000;">forKey</span></span><span style="color:#000000;">:</span><span style="color:#000000;">ExpDefaultCategoriesKey</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[defaultValues </span></span><span style="letter-spacing:0;"><span style="color:#000000;">setObject</span></span><span style="color:#000000;">:[</span><span style="color:#000000;">NSNumber</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">numberWithBool</span></span><span style="color:#000000;">:</span><span style="color:#000000;">NO</span><span style="color:#000000;">] </span><span style="letter-spacing:0;"><span style="color:#000000;">forKey</span></span><span style="color:#000000;">:</span><span style="color:#000000;">ExpOpenLastDocKey</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[defaultValues </span></span><span style="letter-spacing:0;"><span style="color:#000000;">setObject</span></span><span style="color:#000000;">:[</span><span style="color:#000000;">NSNumber</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">numberWithInt</span></span><span style="color:#000000;">:</span><span style="color:#000000;">0</span><span style="color:#000000;">] </span><span style="letter-spacing:0;"><span style="color:#000000;">forKey</span></span><span style="color:#000000;">:</span><span style="color:#000000;">ExpDefaultDateOffset</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[defaultValues </span></span><span style="color:#000000;">setObject</span><span style="letter-spacing:0;"><span style="color:#000000;">:catArray </span></span><span style="color:#000000;">forKey</span><span style="letter-spacing:0;"><span style="color:#000000;">:</span></span><span style="color:#000000;">ExpDefaultCategoriesList</span><span style="letter-spacing:0;"><span style="color:#000000;">];</span></span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// register the defaults</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[[</span></span><span style="color:#000000;">NSUserDefaults</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">standardUserDefaults</span></span><span style="color:#000000;">] </span><span style="letter-spacing:0;"><span style="color:#000000;">registerDefaults</span></span><span style="color:#000000;">:defaultValues];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>PreferenceController</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Now that we have created the standard defaults we need to be able to edit them. to start with we need to do a little editing to the PreferenceController class (again if you haven’t yet, create the files). In PreferenceController.m you just need to add an init method to return the correct nib file:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">id</span><span style="letter-spacing:0;">) init</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="color:#000000;">{</span></span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="color:#000000;">if</span><span style="color:#000000;"> (![</span><span style="color:#000000;">super</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">initWithWindowNibName</span></span><span style="color:#000000;">:</span><span style="color:#000000;">@"Preferences"</span><span style="color:#000000;">])</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">{</span></span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">return</span></span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">nil</span></span><span style="color:#000000;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">}</span></span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">return</span></span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">self</span></span><span style="color:#000000;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="color:#000000;">}</span></span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>AppController part 2</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Back in AppController.h we need to add one outlet and one method:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0 color;">@interface</span><span style="letter-spacing:0;"> AppController : NSObject </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">PreferenceController</span><span style="letter-spacing:0;"> *preferenceController;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">IBAction</span><span style="letter-spacing:0;">) showPreferencePanel:(</span><span style="letter-spacing:0 color;">id</span><span style="letter-spacing:0;">)sender;</span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0;">@end</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Then in AppController.m we need to implement the method:</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">IBAction</span><span style="letter-spacing:0;">) showPreferencePanel:(</span><span style="letter-spacing:0 color;">id</span><span style="letter-spacing:0;">)sender</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="color:#000000;">{</span></span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="color:#000000;">if</span><span style="color:#000000;"> (!</span><span style="letter-spacing:0;"><span style="color:#000000;">preferenceController</span></span><span style="color:#000000;">)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">{</span></span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">preferenceController</span></span><span style="color:#000000;"> = [[</span><span style="letter-spacing:0;"><span style="color:#000000;">PreferenceController</span></span><span style="color:#000000;"> </span><span style="color:#000000;">alloc</span><span style="color:#000000;">] </span><span style="color:#000000;">init</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">}</span></span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[</span></span><span style="letter-spacing:0;"><span style="color:#000000;">preferenceController</span></span><span style="color:#000000;"> </span><span style="color:#000000;">showWindow</span><span style="color:#000000;">:</span><span style="color:#000000;">self</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="color:#000000;">}</span></span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Of course we need to hook up our new method to make it work. Open MainMenu.xib in IB, and add an NSObject from the ‘Objects &amp; Controllers’ part of the Library (just drag it over to the IB document widow to add it). In the Inspector select the Idenity tab set the class to ‘AppController’ (if for  some reason it doesn&#8217;t show up make sure you have saved the AppController.h file). Then, select the application menu (the one with the apps name) and control drag from the ‘Preferences’ menu item to the AppController and select showPreferencePanel: as the action. </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>Preferences.xib</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">We are going to take care of setting preferences with an NSUserDefaultsController and bindings. To start with, if you haven’t already, create the Preferences.xib file, then open it in IB. Drag out the necessary controls to make it look something like this:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;"><img class="aligncenter size-full wp-image-58" title="PreferencesXIB" src="http://themikeswan.files.wordpress.com/2009/06/preferencesxib1.png?w=450" alt="PreferencesXIB"   /><br />
</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">To create the ‘+’ and ‘-’ buttons I used the NSAddTemplate and NSRemoveTemplate as the images.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Next, in IB,  drag over an NSUserDefaultsController to the Preferences.xib document. Also drag over an NSArrayController. In the inspector for the user defaults controller uncheck the “Applied Immediately.” checkbox (if you prefer you can leave it checked and changes to the user defaults will be saved as soon as they are changed. We will start bindings from the top down, so let’s start with the checkbox labeled “Open a new document.” Bind the value to User Defaults Controller.values.EmptyDocumentFlag. </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;"><img class="aligncenter size-full wp-image-59" title="firstPrefBinding" src="http://themikeswan.files.wordpress.com/2009/06/firstprefbinding.png?w=450" alt="firstPrefBinding"   /><br />
</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">You may have noticed that we used the actual value of the string we declared as one of our externs not the extern variable, this is because IB has no knowledge of the externs so we have to use the values of the variables. In order to save problems later I would suggest using copy/paste to make sure you don’t mistype anything. The rest of the bindings should be pretty obvious, but here is the connections HUD for the User Defaults Controller. You should note that the DefaultCategoriesList gets bound to the array controller, this is so we can get add and delete for free. One really important thing to note is that the DefaultDateOffset needs to be bound to both the text field and the stepper, otherwise it won’t work right.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;"><img class="aligncenter size-full wp-image-60" title="BindingsHUD" src="http://themikeswan.files.wordpress.com/2009/06/bindingshud.png?w=450" alt="BindingsHUD"   /><br />
</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">To get the table view to show the default categories select the table column (make sure you select the  column and not the scroll view or table view) and bind its value to the arranged objects of the array controller and set the key to “theString.” Then we need to hook-up all the actions. Control drag from the add button to the array controller and select the add: method do the same with the remove button (connecting it to remove: of course). After that, control drag from the save button to the user defaults controller and select the save: method, the restore defaults button will get connected to the revertToInitialValues: method. For some reason that I do not understand the revertToInitialValues: method does not actually work, the revert: method works great to delete unsaved changes and save: works as it should as well, if anyone has any ideas on what is missing please let me know.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Don’t forget to save everything, Next we will move on to implementing those preferences.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>Implementing the preferences</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Let’s start with the easiest one, opening a blank document on startup. To start with the AppController needs to be the app delegate in order to get the methods calls we will need. You can either do this by implementing the init method and then calling [NSApp setDelegate: self] or open MainMenu.xib in IB, control drag from File’s Owner to the App Controller instance and select delegate as the outlet. Then in AppController.m add the following method:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">BOOL</span><span style="letter-spacing:0;">) applicationShouldOpenUntitledFile:(</span><span style="letter-spacing:0 color;">NSApplication</span><span style="letter-spacing:0;"> *) sender</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">return</span><span style="letter-spacing:0 color;"> [[</span><span style="letter-spacing:0 color;">NSUserDefaults</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">standardUserDefaults</span><span style="letter-spacing:0 color;">] </span><span style="letter-spacing:0;">boolForKey</span><span style="letter-spacing:0 color;">:</span><span style="letter-spacing:0 color;">ExpEmptyDocKey</span><span style="letter-spacing:0 color;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:12px Monaco;min-height:16px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">That takes care of our first preference, now on to opening the last document that was opened when launching. This also takes advantage of one of the methods that gets called on the app delegate, so again in AppController.m add the following method:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">void</span><span style="letter-spacing:0;">)applicationDidFinishLaunching:(</span><span style="letter-spacing:0 color;">NSNotification</span><span style="letter-spacing:0;"> *)aNotification</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{<span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// see if we need to open the most recent document or not and do it if needed</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="color:#000000;">if</span><span style="color:#000000;"> ([[</span><span style="color:#000000;">NSUserDefaults</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">standardUserDefaults</span></span><span style="color:#000000;">] </span><span style="letter-spacing:0;"><span style="color:#000000;">boolForKey</span></span><span style="color:#000000;">:</span><span style="color:#000000;">ExpOpenLastDocKey</span><span style="color:#000000;">])</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">{</span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="color:#000000;">NSArray</span><span style="letter-spacing:0;"><span style="color:#000000;"> *anArray;</span></span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="letter-spacing:0;"><span style="color:#000000;">NSDocumentController</span></span><span style="color:#000000;"> *docController = [</span><span style="letter-spacing:0;"><span style="color:#000000;">NSDocumentController</span></span><span style="color:#000000;"> </span><span style="color:#000000;">sharedDocumentController</span><span style="color:#000000;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">anArray = [docController </span></span><span style="color:#000000;">recentDocumentURLs</span><span style="letter-spacing:0;"><span style="color:#000000;">];</span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="color:#000000;">if</span><span style="letter-spacing:0;"><span style="color:#000000;"> (anArray != </span></span><span style="color:#000000;">nil</span><span style="letter-spacing:0;"><span style="color:#000000;"> &amp;&amp; [anArray </span></span><span style="color:#000000;">count</span><span style="letter-spacing:0;"><span style="color:#000000;">] &gt; </span></span><span style="color:#000000;">0</span><span style="letter-spacing:0;"><span style="color:#000000;">)</span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">{</span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span></span><span style="color:#000000;">NSError</span><span style="letter-spacing:0;"><span style="color:#000000;"> *anError = </span></span><span style="color:#000000;">nil</span><span style="letter-spacing:0;"><span style="color:#000000;">;</span></span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">[docController </span></span><span style="letter-spacing:0;"><span style="color:#000000;">openDocumentWithContentsOfURL</span></span><span style="color:#000000;">:[anArray </span><span style="letter-spacing:0;"><span style="color:#000000;">objectAtIndex</span></span><span style="color:#000000;">:</span><span style="color:#000000;">0</span><span style="color:#000000;">] </span><span style="letter-spacing:0;"><span style="color:#000000;">display</span></span><span style="color:#000000;">:</span><span style="color:#000000;">YES</span><span style="color:#000000;"> </span><span style="letter-spacing:0;"><span style="color:#000000;">error</span></span><span style="color:#000000;">:&amp;anError];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">}</span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"><span style="color:#000000;"> </span></span><span style="color:#000000;">}</span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="color:#000000;">}</span></span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">On order to implement the default date offset we are going to do things a little differently (we may be straying from MVC a bit here, but I think it works). This is the one time we will code the actual value of one of our externs, we are doing this so that the entity class can be reused in other apps more easily (we can declare a different extern in another app but define it the same way and have use of this method there). In Expense.h modify the </span><span style="font:12px Monaco;letter-spacing:0;">awakeFromInsert</span><span style="letter-spacing:0;"> method to look like this:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">void</span><span style="letter-spacing:0;">) awakeFromInsert</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSNumber</span><span style="letter-spacing:0 color;"> *days = [[</span><span style="letter-spacing:0 color;">NSUserDefaults</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">standardUserDefaults</span><span style="letter-spacing:0 color;">] </span><span style="letter-spacing:0;">objectForKey</span><span style="letter-spacing:0 color;">:</span><span style="letter-spacing:0 color;">@&#8221;DefaultDateOffset&#8221;</span><span style="letter-spacing:0 color;">];</span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSLog</span><span style="letter-spacing:0 color;">(</span><span style="letter-spacing:0;">@&#8221;days = %@&#8221;</span><span style="letter-spacing:0 color;">, days);</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">int</span><span style="letter-spacing:0;"> dayInt<span style="white-space:pre;"> </span>= [days </span><span style="letter-spacing:0 color;">intValue</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSLog</span><span style="letter-spacing:0 color;">(</span><span style="letter-spacing:0;">@&#8221;dayInt = %i&#8221;</span><span style="letter-spacing:0 color;">, dayInt);</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">if</span><span style="letter-spacing:0;"> (dayInt == </span><span style="letter-spacing:0 color;">0</span><span style="letter-spacing:0;">)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSDate</span><span style="letter-spacing:0;"> *now = [</span><span style="letter-spacing:0 color;">NSDate</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">date</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;">.date = now;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">else</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="color:#007400;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">int</span><span style="letter-spacing:0 color;"> seconds = dayInt * </span><span style="letter-spacing:0 color;">86400</span><span style="letter-spacing:0 color;">; </span><span style="letter-spacing:0;">// number of days times number of seconds in one day.</span></span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="color:#2e0d6e;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSDate</span><span style="letter-spacing:0 color;"> *theDate = [[</span><span style="letter-spacing:0 color;">NSDate</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">alloc</span><span style="letter-spacing:0 color;">] </span><span style="letter-spacing:0;">initWithTimeIntervalSinceNow</span><span style="letter-spacing:0 color;">:seconds];</span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;">.date = theDate;</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// we called alloc therefore we call release, even though it will be released when this method ends anyway.</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[theDate </span><span style="letter-spacing:0 color;">release</span><span style="letter-spacing:0;">]; </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">For our final trick we will create some default categories for the user in all new documents. There are several steps involved in this but it all happens in one method in MyDocument. We are going to override the  method since it only gets called when new documents are created. Before we start adding categories to the document we will first need to disable undo tracking so the document doesn’t start out dirty, then we add the categories, process the changes, and re-enable undo tracking. I’ve commented the code here pretty well so you can follow along with what is happening easier. In MyDocument.m add the following method definition:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;">// Called only when document is first created</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">id</span><span style="letter-spacing:0;">) initWithType: (</span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> *) typeName error: (</span><span style="letter-spacing:0 color;">NSError</span><span style="letter-spacing:0;"> **) outError</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// call the designated initalizer</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">MyDocument</span><span style="letter-spacing:0;"> *document = [</span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">init</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// pass on the file type</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[</span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">setFileType</span><span style="letter-spacing:0;">:typeName];</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// disable undo tracking</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">NSManagedObjectContext</span><span style="letter-spacing:0 color;"> *context = [</span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">managedObjectContext</span><span style="letter-spacing:0 color;">];</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span>[[context </span><span style="letter-spacing:0;">undoManager</span><span style="letter-spacing:0 color;">] </span><span style="letter-spacing:0;">disableUndoRegistration</span><span style="letter-spacing:0 color;">];</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// check if the user want new documents to have basic entities added</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">NSUserDefaults</span><span style="letter-spacing:0 color;"> *defaults = [</span><span style="letter-spacing:0;">NSUserDefaults</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">standardUserDefaults</span><span style="letter-spacing:0 color;">];</span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">if</span><span style="letter-spacing:0 color;"> ([defaults </span><span style="letter-spacing:0 color;">boolForKey</span><span style="letter-spacing:0 color;">: </span><span style="letter-spacing:0;">ExpDefaultCategoriesKey</span><span style="letter-spacing:0 color;">])</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// if the user wants the default items we hand them over</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// Add the default entities</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *categoryArray = [defaults </span><span style="letter-spacing:0 color;">objectForKey</span><span style="letter-spacing:0;">: </span><span style="letter-spacing:0 color;">ExpDefaultCategoriesList</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSDictionary</span><span style="letter-spacing:0;"> *dictionary;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">for</span><span style="letter-spacing:0;"> (dictionary </span><span style="letter-spacing:0 color;">in</span><span style="letter-spacing:0;"> categoryArray)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">Category</span><span style="letter-spacing:0 color;"> *newCategory = [</span><span style="letter-spacing:0 color;">NSEntityDescription</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">insertNewObjectForEntityForName</span><span style="letter-spacing:0 color;">: </span><span style="letter-spacing:0 color;">@"Category"</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">inManagedObjectContext</span><span style="letter-spacing:0 color;">: [</span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">managedObjectContext</span><span style="letter-spacing:0 color;">]]; </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[newCategory </span><span style="letter-spacing:0 color;">setValue</span><span style="letter-spacing:0;">: [dictionary </span><span style="letter-spacing:0 color;">objectForKey</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">@"theString"</span><span style="letter-spacing:0;">] forKey: </span><span style="letter-spacing:0 color;">@&#8221;name&#8221;</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// enable undo tracking</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span>[context </span><span style="letter-spacing:0;">processPendingChanges</span><span style="letter-spacing:0 color;">];</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span>[[context </span><span style="letter-spacing:0;">undoManager</span><span style="letter-spacing:0 color;">] </span><span style="letter-spacing:0;">enableUndoRegistration</span><span style="letter-spacing:0 color;">];</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">return</span><span style="letter-spacing:0;"> document;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>That’s all folks</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">That brings us to the end of our time together today. In our next session we will do some versioning, and if I can figure out we will add in some other features as well. If for some reason something isn’t working for you at this point here is a zip file of the project at this point, along with a sample file:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong><a href="http://files.getdropbox.com/u/130983/Expenses3.zip" target="_blank">Expenses3.zip</a></strong></span></p>
<p style="text-align:center;font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"><strong> </strong></span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">There are two things I would like to add at this point but don’t know how to; an NSComboBox in place of the NSPopUpMenu in the Expenses tab (it would be nice to be able to type in the Category with autocompletion), the other thing is it would be nice to see how much was spent in each category per month along with the total for each month. I’m sure both of these things are fairly easy but they have eluded me thus far. For the combo box I have tried translating the bindings over but they don’t match and none of my attempts have worked. For the monthly totals I have tried numerous methods that have all failed. inserting attributes for each month with custom getter methods causes an error as soon as the second getter is fired. Attempts to use notifications have failed since they are sent far too often to be useful. I welcome any suggestions or ideas in either of these two areas and will ensure that all contributers get credit.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">As always, I look forward to your comments, questions, complaints, suggestions, etc.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/56/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/56/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/56/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=56&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2009/06/23/expenses-a-core-data-tutorial-part-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2009/06/preferencesxib1.png" medium="image">
			<media:title type="html">PreferencesXIB</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2009/06/firstprefbinding.png" medium="image">
			<media:title type="html">firstPrefBinding</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2009/06/bindingshud.png" medium="image">
			<media:title type="html">BindingsHUD</media:title>
		</media:content>
	</item>
		<item>
		<title>Xcode haters</title>
		<link>http://themikeswan.wordpress.com/2009/06/21/xcode-haters/</link>
		<comments>http://themikeswan.wordpress.com/2009/06/21/xcode-haters/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 04:33:47 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/2009/06/21/xcode-haters/</guid>
		<description><![CDATA[So I use TweetDeck for my twitter account (@michaelswan) and keep searches open for Xcode, Cocoa, CoreData, &#38; Core Data. I have been noticing on the Xcode search that there are a lot of Xcode haters posting with what amounts to &#8220;Xcode sucks compared to ________.&#8221; Generally the blank is filled with Visual Studio and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=53&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I use <a href="http://tweetdeck.com/beta/" target="_blank">TweetDeck</a> for my twitter account (<a href="http://twitter.com/michaelswan/" target="_blank">@michaelswan</a>) and keep searches open for Xcode, Cocoa, CoreData, &amp; Core Data. I have been noticing on the Xcode search that there are a lot of Xcode haters posting with what amounts to &#8220;Xcode sucks compared to ________.&#8221;  Generally the blank is filled with Visual Studio and sometimes Eclipse. I have never used any other IDE, except a brief run in with Think C way back when I first tried to learn programming (that attempt btw failed miserably), so I really have no point of comparison. I have to wonder however is it really that Xcode is not as good as Visual Studio or Eclipse, or is it simply that now the iPhone is out and everyone is trying to get rich quick off of it (I really do think the iPhone is the modern California Gold Rush) that lots of Windows developers are coming over and can&#8217;t wrap their heads around the Mac way of thinking. As a side note before this turns into a which OS is better battle; I love the Mac OS, have never owned anything that wasn&#8217;t Mac (Classic II in 1992), and I hope to never touch a Windows machine again. That said I don&#8217;t think that Windows users are deficient in any way, they just think in a different way than me.<br />
With this in mind I invite you all to leave comments with specific deficiencies in Xcode compared to other IDEs. You should know that I will just delete comments that just say that Xcode sucks, give me a real reason why it sucks. In the end I will try to take the comments boil them down to a consolidated list and submit an enhancement request to Apple, after all, just saying something sucks doesn&#8217;t fix it, isolate the problems and ask for them to be fixed.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=53&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2009/06/21/xcode-haters/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>
	</item>
		<item>
		<title>A Core Data Tutorial Part 2: Polishing the Basics</title>
		<link>http://themikeswan.wordpress.com/2009/05/30/a-core-data-tutorial-part-2-polishing-the-basics/</link>
		<comments>http://themikeswan.wordpress.com/2009/05/30/a-core-data-tutorial-part-2-polishing-the-basics/#comments</comments>
		<pubDate>Sun, 31 May 2009 03:54:46 +0000</pubDate>
		<dc:creator>themikeswan</dc:creator>
				<category><![CDATA[Core Data]]></category>

		<guid isPermaLink="false">http://themikeswan.wordpress.com/?p=39</guid>
		<description><![CDATA[In this installment we will add some polish to our app. This time we will spend most of our time writing code and very little in IB. We will also not be adding anything the user will really notice (unless its missing). Things we will accomplish: Make it so that new expenses will start with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=39&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="font:normal normal normal 13px/normal Arial;text-align:left;margin:0;"><span style="font-family:Helvetica;">In this installment we will add some polish to our app. This time we will spend most of our time writing code and very little in IB. We will also not be adding anything the user will really notice (unless its missing).</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Things we will accomplish:</span></p>
<ul>
<li><span style="letter-spacing:0;">Make it so that new expenses will start with the current date.</span></li>
<li><span style="letter-spacing:0;">Sort expenses by date, and make sure they re-sort as needed with edits.</span></li>
<li><span style="letter-spacing:0;">Alphabetize the categories in both the popup menu and the list in the category tab.</span></li>
<li><span style="letter-spacing:0;">Add the ability to copy and paste expenses.</span></li>
</ul>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Before we actually get started, if you have not already done so run the app, put some random data into a file and save. This will help to illustrate some of the changes we make today, and in future tutorials.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>Entity Defaults</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">So let’s get started with something pretty simple and quick, setting new expense entities to the current date.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">First the Expense entity will need a custom subclass. To start with you will have to select “MyDocument.xcdatamodel,” then select “File -&gt; New File&#8230;” and select “Managed Object Class” as the template. If you didn’t select the data model first you will not see this option.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><strong><img class="aligncenter size-medium wp-image-41" title="Image1" src="http://themikeswan.files.wordpress.com/2009/05/image11.png?w=300&#038;h=222" alt="Image1" width="300" height="222" /><br />
</strong></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">You can leave everything alone in the next pane (you want it to be saved to the project folder and be added to the project. In the last pane select “Expense.” Leave “Generate accessors” and “Generate Obj-C 2.0 Properties” checked and make sure “Generate validation methods” is not checked. Once you click Finish you will have two new files “Expense.h” and “Expense.m,” notice also that the model file now shows that it has been changed. If you select the model and then the Expense entity you will see that the class has been changed from “NSManagedObject” to “Expense.” Save the model file.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><strong><img class="aligncenter size-medium wp-image-42" title="Image2" src="http://themikeswan.files.wordpress.com/2009/05/image2.png?w=300&#038;h=222" alt="Image2" width="300" height="222" /><br />
</strong></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">In “Expense.m” add the following method:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">void</span><span style="letter-spacing:0;">) awakeFromInsert</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSDate</span><span style="letter-spacing:0;"> *now = [</span><span style="letter-spacing:0 color;">NSDate</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">date</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;">.date = now;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0;">@end</span></p>
<p style="font:10px Monaco;color:#aa0d91;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">That’s it, Save, then Build and Go to make sure everything works right and notice that now when you create a new expense it has today’s date by default. As long as we are setting up default values let’s go ahead and set the Category.name default value to “category,” the Expense.amount to “0,” and the Expense.desc to “expense.” Again remember to save, if you want Build and Go, to see the default values get dropped in for you.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><strong><img class="aligncenter size-medium wp-image-43" title="Image3" src="http://themikeswan.files.wordpress.com/2009/05/image3.png?w=300&#038;h=218" alt="Image3" width="300" height="218" /><br />
</strong></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">So why </span><span style="font:10px Monaco;letter-spacing:0;">awakeFromInsert</span><span style="letter-spacing:0;">? </span><span style="font:10px Monaco;letter-spacing:0;">awakeFromInsert</span><span style="letter-spacing:0;"> is only called once in the life of an entity, this way you can do any setup needed for new entities and not worry about it being called when the model is loaded from disk. </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">You should also notice that none of the changes broke any old files we had around. This is important later as we will be adding a new attribute to the Expense entity in a later tutorial that will break any files that we create now if not done properly. For now you just need to know that you have to be careful when making changes to the model, the Apple documentation in Xcode covers what you can and cannot change without breaking the model.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>Sorting</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Now on to some sorting.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">In MyDocument.h add the following outlets:</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0 color;">@interface</span><span style="letter-spacing:0;"> MyDocument : NSPersistentDocument </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">IBOutlet</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">NSTableView</span><span style="letter-spacing:0 color;"> *</span><span style="letter-spacing:0;">expenseTable</span><span style="letter-spacing:0 color;">;</span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">IBOutlet</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">NSTableView</span><span style="letter-spacing:0 color;"> *</span><span style="letter-spacing:0;">categoryTable</span><span style="letter-spacing:0 color;">;</span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">IBOutlet</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">NSTableView</span><span style="letter-spacing:0 color;"> *</span><span style="letter-spacing:0;">expenseByCatTable</span><span style="letter-spacing:0 color;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">IBOutlet</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">NSArrayController</span><span style="letter-spacing:0;"> *categoryPopUpController;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">In MyDocument.m edit the</span><span style="font:10px Monaco;letter-spacing:0;"> windowControllerDidLoadNib:</span><span style="letter-spacing:0;"> method to look like this:</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">void</span><span style="letter-spacing:0;">)windowControllerDidLoadNib:(</span><span style="letter-spacing:0 color;">NSWindowController</span><span style="letter-spacing:0;"> *)windowController </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"> [</span><span style="letter-spacing:0 color;">super</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">windowControllerDidLoadNib</span><span style="letter-spacing:0 color;">:windowController];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">// user interface preparation code</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// create two sort descriptors, one for date and one for name</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSSortDescriptor</span><span style="letter-spacing:0;"> *dateSort = [[</span><span style="letter-spacing:0 color;">NSSortDescriptor</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">alloc</span><span style="letter-spacing:0;">] </span><span style="letter-spacing:0 color;">initWithKey</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">@&#8221;date&#8221;</span><span style="letter-spacing:0;"> <span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">ascending</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">YES</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSSortDescriptor</span><span style="letter-spacing:0;"> *nameSort = [[</span><span style="letter-spacing:0 color;">NSSortDescriptor</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">alloc</span><span style="letter-spacing:0;">]</span><span style="letter-spacing:0 color;">initWithKey</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">@&#8221;name&#8221;</span><span style="letter-spacing:0;"> <span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">ascending</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">YES</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// Put the sort descriptors into arrays</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *dateDescriptors = [</span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">arrayWithObject</span><span style="letter-spacing:0;">:dateSort];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *nameDescriptors = [</span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">arrayWithObject</span><span style="letter-spacing:0;">:nameSort];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// Now set the corrent sort descriptors for each outlet</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// First set the tables that shows expenses to the date descriptor</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[</span><span style="letter-spacing:0 color;">expenseTable</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">setSortDescriptors</span><span style="letter-spacing:0;">:dateDescriptors];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[</span><span style="letter-spacing:0 color;">expenseByCatTable</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">setSortDescriptors</span><span style="letter-spacing:0;">:dateDescriptors];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// Now set the descriptors for the Category table</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[</span><span style="letter-spacing:0 color;">categoryTable</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">setSortDescriptors</span><span style="letter-spacing:0;">:nameDescriptors];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// For the Category popup button we have to sort the array controller not the button.</span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span>[</span><span style="letter-spacing:0;">categoryPopUpController</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">setSortDescriptors</span><span style="letter-spacing:0 color;">:nameDescriptors];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Next, open MyDocument.xib in IB and connect the outlets.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><strong><img class="aligncenter size-medium wp-image-44" title="Image4" src="http://themikeswan.files.wordpress.com/2009/05/image4.png?w=300&#038;h=204" alt="Image4" width="300" height="204" /><br />
</strong></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">To make sure that everything re-sorts when things are edited turn on “Auto Rearrange Content” in each array controller:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"><strong> </strong></span></p>
<p style="font:12px Helvetica;margin:0;"><strong><img class="aligncenter size-full wp-image-45" title="Image6" src="http://themikeswan.files.wordpress.com/2009/05/image6.png?w=450" alt="Image6"   /><br />
</strong></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>Copy &amp; Paste</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Finally let’s make it so that the user doesn’t have to put all the same information in all the time when the same expense shows up over and over again with some Copy/Paste action. This is pulled straight from the Apple Documentation with only a few adjustments to make it work here.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">To start with add the following method declarations to “Expense.h”</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">+ (</span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *) keysToBeCopied;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">NSDictionary</span><span style="letter-spacing:0;"> *) dictionaryRepresentation;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> *) stringDescription;</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Then implement them in “Expense.m”</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;">// Copy/Paste methods</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">+ (</span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *) keysToBeCopied</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">static</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *keysToBeCopied = </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">if</span><span style="letter-spacing:0;"> (keysToBeCopied == </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// This will determine which attributes get copied. Must NOT copy relationships or it will copy the actual entity</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// Date has been left out so that the date will default to the current date.</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>keysToBeCopied = [[</span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">alloc</span><span style="letter-spacing:0;">] </span><span style="letter-spacing:0 color;">initWithObjects</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">@&#8221;desc&#8221;</span><span style="letter-spacing:0;">, </span><span style="letter-spacing:0 color;">@&#8221;amount&#8221;</span><span style="letter-spacing:0;">, </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">return</span><span style="letter-spacing:0;"> keysToBeCopied;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">NSDictionary</span><span style="letter-spacing:0;"> *) dictionaryRepresentation</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">return</span><span style="letter-spacing:0 color;"> [</span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">dictionaryWithValuesForKeys</span><span style="letter-spacing:0 color;">:[[</span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">class</span><span style="letter-spacing:0 color;">] </span><span style="letter-spacing:0 color;">keysToBeCopied</span><span style="letter-spacing:0 color;">]];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (</span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> *) stringDescription</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// This will return the title of the category as a string</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> *stringDescription = </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSManagedObject</span><span style="letter-spacing:0;"> *category = </span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;">.category;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">if</span><span style="letter-spacing:0;"> (category != </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>stringDescription = category.</span><span style="letter-spacing:0 color;">name</span><span style="letter-spacing:0;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">return</span><span style="letter-spacing:0;"> stringDescription;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Now add one outlet and two method declarations to “MyDocument.h.”</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// Outlets for copy &amp; paste</span></p>
<p style="font:10px Monaco;color:#3f6e74;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">IBOutlet</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">NSArrayController</span><span style="letter-spacing:0 color;"> *</span><span style="letter-spacing:0;">expensesArrayController</span><span style="letter-spacing:0 color;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (<span style="color:#aa0d91;">IBAction<span style="color:#000000;"><span style="letter-spacing:0;">) copy:(</span><span style="letter-spacing:0 color;">id</span><span style="letter-spacing:0;">) sender;</span></span></span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (<span style="color:#aa0d91;">IBAction<span style="color:#000000;"><span style="letter-spacing:0;">) paste:(</span><span style="letter-spacing:0 color;">id</span><span style="letter-spacing:0;">) sender;</span></span></span></span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0;">@end</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Implement those methods in “MyDocument.m.”</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0;">// For duplicating Expense entities</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (<span style="color:#aa0d91;">IBAction<span style="color:#000000;"><span style="letter-spacing:0;">) copy:(</span><span style="letter-spacing:0 color;">id</span><span style="letter-spacing:0;">) sender</span></span></span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *selectedObjects = [</span><span style="letter-spacing:0 color;">expensesArrayController</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">selectedObjects</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSUInteger</span><span style="letter-spacing:0;"> count = [selectedObjects </span><span style="letter-spacing:0 color;">count</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">if</span><span style="letter-spacing:0;"> (count == </span><span style="letter-spacing:0 color;">0</span><span style="letter-spacing:0;">)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">return</span><span style="letter-spacing:0 color;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSMutableArray</span><span style="letter-spacing:0;"> *copyObjectsArray = [</span><span style="letter-spacing:0 color;">NSMutableArray</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">arrayWithCapacity</span><span style="letter-spacing:0;">:count];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSMutableArray</span><span style="letter-spacing:0;"> *copyStringsArray = [</span><span style="letter-spacing:0 color;">NSMutableArray</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">arrayWithCapacity</span><span style="letter-spacing:0;">:count];</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">for</span><span style="letter-spacing:0;"> (</span><span style="letter-spacing:0 color;">Expense</span><span style="letter-spacing:0;"> *expense </span><span style="letter-spacing:0 color;">in</span><span style="letter-spacing:0;"> selectedObjects)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[copyObjectsArray </span><span style="letter-spacing:0 color;">addObject</span><span style="letter-spacing:0;">:[expense </span><span style="letter-spacing:0 color;">dictionaryRepresentation</span><span style="letter-spacing:0;">]];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[copyStringsArray </span><span style="letter-spacing:0 color;">addObject</span><span style="letter-spacing:0;">:[expense </span><span style="letter-spacing:0 color;">stringDescription</span><span style="letter-spacing:0;">]];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSPasteboard</span><span style="letter-spacing:0;"> *generalPasteboard = [</span><span style="letter-spacing:0 color;">NSPasteboard</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">generalPasteboard</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[generalPasteboard </span><span style="letter-spacing:0 color;">declareTypes</span><span style="letter-spacing:0;">:[</span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">arrayWithObjects</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">MSExpensesPBoardType</span><span style="letter-spacing:0;">, </span><span style="letter-spacing:0 color;">NSStringPboardType</span><span style="letter-spacing:0;">, </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">] </span><span style="letter-spacing:0 color;">owner</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSData</span><span style="letter-spacing:0;"> *copyData = [</span><span style="letter-spacing:0 color;">NSKeyedArchiver</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">archivedDataWithRootObject</span><span style="letter-spacing:0;">:copyObjectsArray];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[generalPasteboard </span><span style="letter-spacing:0 color;">setData</span><span style="letter-spacing:0;">:copyData </span><span style="letter-spacing:0 color;">forType</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">MSExpensesPBoardType</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[generalPasteboard </span><span style="letter-spacing:0 color;">setString</span><span style="letter-spacing:0;">:[copyStringsArray </span><span style="letter-spacing:0 color;">componentsJoinedByString</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">@"\n"</span><span style="letter-spacing:0;">] </span><span style="letter-spacing:0 color;">forType</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">NSStringPboardType</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">- (<span style="color:#aa0d91;">IBAction<span style="color:#000000;"><span style="letter-spacing:0;">) paste:(</span><span style="letter-spacing:0 color;">id</span><span style="letter-spacing:0;">) sender</span></span></span></span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">{</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSPasteboard</span><span style="letter-spacing:0;"> *generalPasteboard = [</span><span style="letter-spacing:0 color;">NSPasteboard</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">generalPasteboard</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSData</span><span style="letter-spacing:0;"> *data = [generalPasteboard </span><span style="letter-spacing:0 color;">dataForType</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">MSExpensesPBoardType</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">if</span><span style="letter-spacing:0;"> (data == </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">return</span><span style="letter-spacing:0 color;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *expensesArray = [</span><span style="letter-spacing:0 color;">NSKeyedUnarchiver</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">unarchiveObjectWithData</span><span style="letter-spacing:0;">:data];</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">NSManagedObjectContext</span><span style="letter-spacing:0 color;"> *moc = [</span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">managedObjectContext</span><span style="letter-spacing:0 color;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *stringArray = [[generalPasteboard </span><span style="letter-spacing:0 color;">stringForType</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">NSStringPboardType</span><span style="letter-spacing:0;">] </span><span style="letter-spacing:0 color;">componentsSeparatedByString</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">@&#8221;\n&#8221;</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">NSEntityDescription</span><span style="letter-spacing:0 color;"> *cats = [</span><span style="letter-spacing:0;">NSEntityDescription</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">entityForName</span><span style="letter-spacing:0 color;">:</span><span style="letter-spacing:0 color;">@"Category"</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">inManagedObjectContext</span><span style="letter-spacing:0 color;">:moc];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> *predString = [</span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">stringWithFormat</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">@"%@ LIKE %%@"</span><span style="letter-spacing:0;">, </span><span style="letter-spacing:0 color;">@"name"</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">int</span><span style="letter-spacing:0;"> i = </span><span style="letter-spacing:0 color;">0</span><span style="letter-spacing:0;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">for</span><span style="letter-spacing:0;"> (</span><span style="letter-spacing:0 color;">NSDictionary</span><span style="letter-spacing:0;"> *expenseDictionary </span><span style="letter-spacing:0 color;">in</span><span style="letter-spacing:0;"> expensesArray)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">//create a new Expense entity</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">Expense</span><span style="letter-spacing:0;"> *newExpense;</span></p>
<p style="font:10px Monaco;color:#2e0d6e;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span>newExpense = (</span><span style="letter-spacing:0 color;">Expense</span><span style="letter-spacing:0 color;"> *)[</span><span style="letter-spacing:0 color;">NSEntityDescription</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">insertNewObjectForEntityForName</span><span style="letter-spacing:0 color;">:</span><span style="letter-spacing:0 color;">@"Expense"</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0;">inManagedObjectContext</span><span style="letter-spacing:0 color;">:moc];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// Dump the values from the dictionary into the new entity</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[newExpense </span><span style="letter-spacing:0 color;">setValuesForKeysWithDictionary</span><span style="letter-spacing:0;">:expenseDictionary];</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// create a fetch request to get the category whose title matches the one in the array at the current index</span></p>
<p style="font:10px Monaco;color:#5c2699;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">NSFetchRequest</span><span style="letter-spacing:0 color;"> *req = [[</span><span style="letter-spacing:0;">NSFetchRequest</span><span style="letter-spacing:0 color;"> </span><span style="letter-spacing:0 color;">alloc</span><span style="letter-spacing:0 color;">] </span><span style="letter-spacing:0 color;">init</span><span style="letter-spacing:0 color;">];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// set the entity</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[req </span><span style="letter-spacing:0 color;">setEntity</span><span style="letter-spacing:0;">:cats];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// create the predicate</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSPredicate</span><span style="letter-spacing:0;"> *predicate = [</span><span style="letter-spacing:0 color;">NSPredicate</span><span style="letter-spacing:0;"> </span><span style="letter-spacing:0 color;">predicateWithFormat</span><span style="letter-spacing:0;">:predString, [stringArray </span><span style="letter-spacing:0 color;">objectAtIndex</span><span style="letter-spacing:0;">:i]];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// set the predicate</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[req </span><span style="letter-spacing:0 color;">setPredicate</span><span style="letter-spacing:0;">:predicate];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// just in case</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSError</span><span style="letter-spacing:0;"> *error = </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">;</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// execute the request</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSArray</span><span style="letter-spacing:0;"> *fetchResults = [moc </span><span style="letter-spacing:0 color;">executeFetchRequest</span><span style="letter-spacing:0;">:req </span><span style="letter-spacing:0 color;">error</span><span style="letter-spacing:0;">:&amp;error];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// acquire a pointer for the correct category</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">Category</span><span style="letter-spacing:0;"> *theCat = [fetchResults </span><span style="letter-spacing:0 color;">objectAtIndex</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">0</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// get the expenses set from the category</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSMutableSet</span><span style="letter-spacing:0;"> *aSet = [theCat </span><span style="letter-spacing:0 color;">mutableSetValueForKey</span><span style="letter-spacing:0;">:</span><span style="letter-spacing:0 color;">@"expenses"</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;color:#007400;margin:0;"><span style="letter-spacing:0 color;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0;">// now to add the new expense entity to the category</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>[aSet </span><span style="letter-spacing:0 color;">addObject</span><span style="letter-spacing:0;">:newExpense];</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>i++;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">}</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">You also need to add a couple of things above </span><span style="font:10px Monaco;letter-spacing:0 color;">@implementation</span><span style="letter-spacing:0;"> in “MyDocument.m.”</span></p>
<p style="font:10px Monaco;color:#c41a16;margin:0;"><span style="letter-spacing:0 color;">#import </span><span style="letter-spacing:0;">&#8220;Expense.h&#8221;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;">NSString *MSExpensesPBoardType = </span><span style="letter-spacing:0 color;">@&#8221;MSExpensesPBoardType&#8221;</span><span style="letter-spacing:0;">;</span></p>
<p style="font:10px Monaco;color:#aa0d91;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Open MyDocument.xib in IB and connect the outlet we added (</span><span style="font:10px Monaco;letter-spacing:0 color;">expensesArrayController</span><span style="letter-spacing:0;">) to the “ExpenseView Array Controller.”</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Save everything, then Build &amp; Go.</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">You should have just gotten an error that looks something like this:</span></p>
<p style="font:12px Helvetica;margin:0;">
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;"><img class="aligncenter size-full wp-image-47" title="Image5" src="http://themikeswan.files.wordpress.com/2009/05/image51.png?w=450" alt="Image5"   /><br />
</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">This seems odd, especially since if you use code completion you probably got the completion for “name” and it is colored to indicate that the editor knows that it is an attribute. No matter, let’s try to fix that error so we can see copy/paste in action. Change the line with the error from dot syntax to a method call:</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0 color;">NSManagedObject</span><span style="letter-spacing:0;"> *category = </span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;">.category;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">if</span><span style="letter-spacing:0;"> (category != </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">)</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>{</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>stringDescription = [category </span><span style="letter-spacing:0 color;">name</span><span style="letter-spacing:0;">];</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span>}</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Now Save and Build.</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Well, at least it is just a warning now. It actually will work like this but we don’t like warnings so let’s see about getting rid of it.</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">First off, why are we getting the warning? The answer is that </span><span style="font:10px Monaco;letter-spacing:0 color;">NSManagedObject</span><span style="letter-spacing:0;"> doesn’t have a method declaration for </span><span style="font:10px Monaco;letter-spacing:0 color;">name</span><span style="letter-spacing:0;"> and really why would it, its not the Category class, its the super class. </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">In order to fix it we need to tell the complier that there is a class named Category and that it has a method called name. Of course we don’t have a file named “Category.h” to import so we will have to make it (seems a little silly but maybe we will need it later for something anyway).</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Don’t forget that in order to get the Managed Object in the New File assistant you need to have the model selected. </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">This works just like last time when we made the files for “Expense.” (Hint: select the model, then New File…, Managed Object, Category, default settings).</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">You don’t need to add any code to either file just add </span><span style="font:10px Monaco;letter-spacing:0 color;">#import </span><span style="font:10px Monaco;letter-spacing:0 color;">&#8220;Category.h&#8221; </span><span style="letter-spacing:0;">to “Expense.h.”</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Then we need to change the two places we refer to </span><span style="font:10px Monaco;letter-spacing:0 color;">NSManagedObject</span><span style="letter-spacing:0;"> to say </span><span style="font:10px Monaco;letter-spacing:0 color;">Category</span><span style="letter-spacing:0;"> instead:</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">In “Expense.h”</span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0;">@property</span><span style="letter-spacing:0 color;"> (</span><span style="letter-spacing:0;">nonatomic</span><span style="letter-spacing:0 color;">, </span><span style="letter-spacing:0;">retain</span><span style="letter-spacing:0 color;">) </span><span style="letter-spacing:0 color;">NSManagedObject</span><span style="letter-spacing:0 color;"> * category;</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">becomes:</span></p>
<p style="font:10px Monaco;color:#aa0d91;margin:0;"><span style="letter-spacing:0;">@property</span><span style="letter-spacing:0 color;"> (</span><span style="letter-spacing:0;">nonatomic</span><span style="letter-spacing:0 color;">, </span><span style="letter-spacing:0;">retain</span><span style="letter-spacing:0 color;">) </span><span style="letter-spacing:0 color;">Category</span><span style="letter-spacing:0 color;"> * category;</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Then in “Expense.m”</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> *stringDescription = </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSManagedObject</span><span style="letter-spacing:0;"> *category = </span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;">.category;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">if</span><span style="letter-spacing:0;"> (category != </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">)</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">becomes:</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">NSString</span><span style="letter-spacing:0;"> *stringDescription = </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">Category</span><span style="letter-spacing:0;"> *category = </span><span style="letter-spacing:0 color;">self</span><span style="letter-spacing:0;">.category;</span></p>
<p style="font:10px Monaco;margin:0;"><span style="letter-spacing:0;"><span style="white-space:pre;"> </span></span><span style="letter-spacing:0 color;">if</span><span style="letter-spacing:0;"> (category != </span><span style="letter-spacing:0 color;">nil</span><span style="letter-spacing:0;">)</span></p>
<p style="font:10px Monaco;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Now save everything then Build &amp; Go.</span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">That’s more like it, no errors and no warnings. Wait, you did get a warning and error free build that time right?</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">You should now be able to copy and paste expenses, even several at a time. The date should get set to the current date and everything else should be just like the source expense.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="text-align:center;font:14px Helvetica;margin:0;"><span style="letter-spacing:0;"><strong>That’s all folks</strong></span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">That’s all for this time, next time we will move on to adding user preferences. If for some reason something isn’t working for you at this point here is a zip file of the project at this point, along with a sample file:</span></p>
<p style="font:12px Helvetica;margin:0;"><a href="http://dl.getdropbox.com/u/130983/ExpensesPart2.zip">Expenses Part 2</a></p>
<p style="text-align:center;font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"><strong> </strong></span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">There are two things I would like to add at this point but don’t know how to; an NSComboBox in place of the NSPopUpMenu in the Expenses tab (it would be nice to be able to type in the Category with autocompletion), the other thing is it would be nice to see how much was spent in each category per month along with the total for each month. I’m sure both of these things are fairly easy but they have eluded me thus far. For the combo box I have tried translating the bindings over but they don’t match and none of my attempts have worked. For the monthly totals I have tried numerous methods that have all failed. inserting attributes for each month with custom getter methods causes an error as soon as the second getter is fired. Attempts to use notifications have failed since they are sent far too often to be useful. I welcome any suggestions or ideas in either of these two areas and will ensure that all contributers get credit.</span></p>
<p style="font:12px Helvetica;min-height:14px;margin:0;"><span style="letter-spacing:0;"> </span></p>
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">As always, I look forward to your comments, questions, complaints, suggestions, etc. </span></p>
<p style="font:12px Helvetica;margin:0;">
<p style="font:12px Helvetica;margin:0;"><span style="letter-spacing:0;">Also if anyone knows of a better blog site to keep these tutorials please let me know, this site is annoying the crap out of me.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/themikeswan.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/themikeswan.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/themikeswan.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/themikeswan.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/themikeswan.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/themikeswan.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/themikeswan.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/themikeswan.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/themikeswan.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/themikeswan.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/themikeswan.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/themikeswan.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/themikeswan.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/themikeswan.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=themikeswan.wordpress.com&amp;blog=4438462&amp;post=39&amp;subd=themikeswan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://themikeswan.wordpress.com/2009/05/30/a-core-data-tutorial-part-2-polishing-the-basics/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ad169b11e74c2dc08b4255c14d974df?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=PG" medium="image">
			<media:title type="html">themikeswan</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2009/05/image11.png?w=300" medium="image">
			<media:title type="html">Image1</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2009/05/image2.png?w=300" medium="image">
			<media:title type="html">Image2</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2009/05/image3.png?w=300" medium="image">
			<media:title type="html">Image3</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2009/05/image4.png?w=300" medium="image">
			<media:title type="html">Image4</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2009/05/image6.png" medium="image">
			<media:title type="html">Image6</media:title>
		</media:content>

		<media:content url="http://themikeswan.files.wordpress.com/2009/05/image51.png" medium="image">
			<media:title type="html">Image5</media:title>
		</media:content>
	</item>
	</channel>
</rss>
