<?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/"
	>

<channel>
	<title>nvie.com &#187; iPhone</title>
	<atom:link href="http://nvie.com/archives/category/iphone/feed" rel="self" type="application/rss+xml" />
	<link>http://nvie.com</link>
	<description>Anything that interests me.</description>
	<lastBuildDate>Tue, 24 Aug 2010 11:21:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Auto-generate classes for your Core Data data model, revisited</title>
		<link>http://nvie.com/archives/310</link>
		<comments>http://nvie.com/archives/310#comments</comments>
		<pubDate>Mon, 19 Oct 2009 22:20:32 +0000</pubDate>
		<dc:creator>Vincent Driessen</dc:creator>
				<category><![CDATA[Core Data]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Xcode]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[mogenerator]]></category>

		<guid isPermaLink="false">http://nvie.com/?p=310</guid>
		<description><![CDATA[A few months ago, I wrote about automatically generating classes for your Core Data entities and how to automate Xcode using users scripts, such that, when your model changed, you only needed to run your custom script again and your intermediate model files would reflect the new situation. Well, the guys from the mogenerator project [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago, I wrote about <a title="Automatically generate classes for your Core Data data model" href="/archives/263">automatically generating classes for your Core Data entities</a> and how to automate Xcode using users scripts, such that, when your model changed, you only needed to run your custom script again and your intermediate model files would reflect the new situation.</p>
<p>Well, the guys from the <a title="mogenerator project at Github" href="http://github.com/rentzsch/mogenerator">mogenerator</a> project have come up with a far superior solution in the mean time. The newest version of mogenerator comes with an Xcode plugin named Xmo&#8217;d, which monitors your *.xcdatamodel file for changes and, as soon as it changes, regenerates all of the neccessary files.</p>
<p><strong>This means that there is officially no more reason not to use mogenerator.</strong></p>
<p>To set it up, download the installer package from their (improved) <a title="mogenerator project home page" href="http://rentzsch.github.com/mogenerator/">project website</a> and install it. (Before installing, please read the important release note about the renamed method <code>+newInManagedObjectContext:</code>.)</p>
<p>When installed, all you need to do is Command-click your *.xcdatamodel file, click Get Info, switch to the Comments tab and add the string &#8220;xmod&#8221; to the comment field. This is the trigger for Xmo&#8217;d to start (re)generating your machine-classes (the underscored class files) when the data model changes. Brilliant!</p>
<p><a href="http://nvie.com/wp-content/uploads/2009/10/comment-field.png"><img class="alignnone size-full wp-image-311" title="Adding the trigger to the comment field." src="http://nvie.com/wp-content/uploads/2009/10/comment-field.png" alt="Adding the trigger to the comment field." width="381" height="545" /></a></p>
<p>Oh, the default location at which the generated files will be emitted, is in a folder named after your project, right next to where your *.xcdatamodel already sits:</p>
<p><a href="http://nvie.com/wp-content/uploads/2009/10/emission-location.png"><img class="alignnone size-medium wp-image-314" title="Location where output files are generated" src="http://nvie.com/wp-content/uploads/2009/10/emission-location-300x239.png" alt="Location where output files are generated" width="300" height="239" /></a></p>
<p>Enjoy it and spread the word!</p>
]]></content:encoded>
			<wfw:commentRss>http://nvie.com/archives/310/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSManagedObjectContext extensions</title>
		<link>http://nvie.com/archives/243</link>
		<comments>http://nvie.com/archives/243#comments</comments>
		<pubDate>Tue, 21 Jul 2009 23:32:49 +0000</pubDate>
		<dc:creator>Vincent Driessen</dc:creator>
				<category><![CDATA[Core Data]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://nvie.com/?p=243</guid>
		<description><![CDATA[The Core Data framework rules, and its API is really really powerful. But really, why does the Core Data API require us to write so much boilerplate code? Simple things need to be simple. Why is the deletion of a managed object from the NSManagedObjectContext so easy: &#91;context deleteObject:someObject&#93;; Compared to its creation: &#91;NSEntityDescription insertNewObjectForEntityForName:@&#34;someObjectClassName&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>The Core Data framework rules, and its API is really really powerful. But really, why does the Core Data API require us to write so much boilerplate code? Simple things need to be simple.</p>
<p>Why is the deletion of a managed object from the NSManagedObjectContext so easy:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>context deleteObject<span style="color: #002200;">:</span>someObject<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Compared to its creation:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSEntityDescription</span> insertNewObjectForEntityForName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;someObjectClassName&quot;</span>
                              inManagedObjectContext<span style="color: #002200;">:</span>context<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h3>Extending NSManagedObjectContext</h3>
<p>Add the following category on NSManagedObjectContext to all of your Core Data projects and your pains will be history.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@implementation</span> <span style="color: #400080;">NSManagedObjectContext</span> <span style="color: #002200;">&#40;</span>NSManagedObjectContextConvenienceMethods<span style="color: #002200;">&#41;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>newObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">Class</span><span style="color: #002200;">&#41;</span>entity <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSEntityDescription</span> insertNewObjectForEntityForName<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>entity description<span style="color: #002200;">&#93;</span>
                                         inManagedObjectContext<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Now, a call to create a new object is as easy as deleting it.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>context newObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>someEntity class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<h3>Further enhancements of NSManagedObject</h3>
<p>Matt Gallagher has written an <a href="http://cocoawithlove.com/2008/03/core-data-one-line-fetch.html">excellent article</a> about how to further enhance NSManagedObject for adding simple, one-line fetch support. Be sure to check it out.</p>
]]></content:encoded>
			<wfw:commentRss>http://nvie.com/archives/243/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
