<?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>Software Warlock &#187; Xcode</title>
	<atom:link href="http://softwareblog.morlok.net/category/xcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://softwareblog.morlok.net</link>
	<description></description>
	<lastBuildDate>Sat, 10 Jul 2010 15:34:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CoreData Development Techniques</title>
		<link>http://softwareblog.morlok.net/2009/04/01/coredata-development-techniques/</link>
		<comments>http://softwareblog.morlok.net/2009/04/01/coredata-development-techniques/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 03:58:08 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Software Development Tools]]></category>
		<category><![CDATA[Xcode]]></category>
		<category><![CDATA[CoreData]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=145</guid>
		<description><![CDATA[
I&#8217;m just getting started with CoreData, and I&#8217;ve been excited about about its nice graphical environment to define your model.



CoreData&#8217;s approach to ORM is somewhat different than other tools, such as Hibernate, because it takes advantage of Objective-C&#8217;s dynamic nature, and avoids some of the clutter problems you experience with more statically typed languages.  [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;m just getting started with CoreData, and I&#8217;ve been excited about about its nice graphical environment to define your model.
</p>
<p><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/04/coredata-model.png"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/04/coredata-model-300x225.png" alt="" title="CoreData model" width="300" height="225" class="aligncenter size-medium wp-image-147" /></a></p>
<p>
CoreData&#8217;s approach to ORM is somewhat different than other tools, such as <a href="http://www.hibernate.org/">Hibernate</a>, because it takes advantage of Objective-C&#8217;s dynamic nature, and avoids some of the clutter problems you experience with more statically typed languages.  Instead of providing mapping information for classes that are defined elsewhere, all modeled objects are instances of <a href="http://developer.apple.com/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObject_Class/index.html">NSManagedObject</a> and the system customizes the accessors on the created objects based on the schema.
</p>
<p>
This is very nice when you are defining your model, and when you can use things like Cocoa Bindings to provide much of the system&#8217;s behavior based on state of the model, but when you need to start writing custom controller logic, it isn&#8217;t very readable to have everything going around as an NSManagedObject.  You can use the dynamically generated properties on these objects, but you will get compiler warnings.  Annoying.
</p>
<p>
You can certainly subclass NSManagedObject and tell the model to use your implementation.  This is necessarily if you are going to provide custom behavior on the model objects above the simple data oriented behavior CoreData provides for you.  Xcode will even <a href="http://developer.apple.com/DOCUMENTATION/DeveloperTools/Conceptual/XcodeCoreDataTools/Articles/xcdCodeGeneration.html#//apple_ref/doc/uid/TP40006872-SW1">generate source code</a> for you from your data model.
</p>
<p>While in the data model editor, do <em>File</em>, <em>New File&#8230;</em> and select <em>Managed Object Class</em> from the <em>Cocoa</em> category.</p>
<p><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/04/picture-1.png"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/04/picture-1-300x283.png" alt="" title="select Managed Object Class" width="300" height="283" class="aligncenter size-medium wp-image-159" /></a></p>
<p>Choose the location where your files will be generated.</p>
<p>Select the model entities for which classes will be generated and click <em>Finish</em>.</p>
<p><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/04/picture-2.png"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/04/picture-2-300x283.png" alt="" title="Select entities to generate" width="300" height="283" class="aligncenter size-medium wp-image-160" /></a></p>
<p>
The problem with this approach is that you are stuck manually keeping the model and the custom classes in sync.  You can certainly regenerate, but if you have made any changes to the files, they will be overwritten.
</p>
<p>One alternative to this manual update process is a tool, <a href="http://rentzsch.com/code/mogenerator">mogenerator</a>, that will automatically generate custom classes for you.  It even goes so far as two generate two classes for each model object:<br /> NSManagedObject&nbsp;<&mdash;&nbsp;GenClassA&nbsp;<&mdash;&nbsp;GenClassB (where <&mdash; represents inherits from).  This allows you to modify the code in GenClassB and leave GenClassA alone, which stores the core information from the model.  This way you can regenerate GenClassA as needed, without overwriting your custom behavior in GenClassB.  <a href="http://www.pyrusmalus.com/index.html">PyrusMalus</a> has an <a href="http://www.pyrusmalus.com/blog/archives/2006/11/06/getting_started_with_mogenerator.html">introduction</a> on how to get started with mogenerator, <a href="http://importantshock.wordpress.com/">Important Shock</a> has a discussion about the <a href="http://importantshock.wordpress.com/2006/12/19/mogenerator-or-how-i-nearly-abandoned-core-data/">approach used</a> by the tool, and <a href="http://guelich.net/blog/">Cocoa &amp; Medicine</a> has a <a href="http://guelich.net/blog/2007/01/01/running-mogenerator-from-xcode">description</a> of how to run mogerator from within Xcode using Apple Script.
</p>
<p>
There is some dissension about if the method of generating custom classes is a good thing.  On <a href="http://www.cocoabuilder.com/archive/message/cocoa/2008/10/5/219503">this thread</a> on <a href="http://www.cocoabuilder.com/">CocoaBuilder</a> Ben (who appears to be from Apple according to <a href="http://www.linkedin.com/profile?viewProfile=&#038;key=852945&#038;authToken=EW78&#038;authType=NAME_SEARCH&#038;pvs=ps">LinkedIn</a>) seems to be against the idea, though I his main objection is to the idea that the custom accessors generated by NSManagedObject are slower than those statically generated by mogenerator.
</p>
<p>
One of Apples <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdAccessorMethods.html#//apple_ref/doc/uid/TP40002154">recommended approaches</a> to avoid compiler warnings is to created categories for NSManagedObject so that the compiler accepts that the accessors you are using are actually there.  Xcode provides the ability to copy the attribute declarations for use in these categories (or in custom classes), but to cover everything, you need to copy two separate sets of declarations and paste them into the code.  You could use the Xcode custom class generation to get the signatures you need, but there is a still a bit of manual work in the process.
</p>
<p>
In my opinion, Apple needs to work more to help developers with this problem.  I like the approach taken by mogenerator, and I would like to see that same regenerative ability in the built-in Xcode tools, using the 2-class generation-gap design pattern to allow you to make changes to the generated classes without having the changes overwritten next time you re-generate.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/04/01/coredata-development-techniques/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xcode Keyboard Shortcuts</title>
		<link>http://softwareblog.morlok.net/2009/01/28/xcode-keyboard-shortcuts/</link>
		<comments>http://softwareblog.morlok.net/2009/01/28/xcode-keyboard-shortcuts/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 04:19:11 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=72</guid>
		<description><![CDATA[Right now I&#8217;m working on becoming efficient at using Xcode.  I&#8217;m sure it will take me a while to get really fast in it, but for now I figured I&#8217;d better start collecting useful resources.
Here is a good list of keyboard shortcuts for Xcode via this site. Update: the Pages file from which the [...]]]></description>
			<content:encoded><![CDATA[<p>Right now I&#8217;m working on becoming efficient at using Xcode.  I&#8217;m sure it will take me a while to get really fast in it, but for now I figured I&#8217;d better start collecting useful resources.</p>
<p><a href="http://www.1729.us/xcode/Xcode%20Shortcuts.png">Here</a> is a good list of keyboard shortcuts for Xcode via <a href="http://cocoasamurai.blogspot.com/2008/02/complete-xcode-keyboard-shortcut-list.html">this</a> site. <b>Update:</b> the Pages file from which the PNG was generated is available <a href="http://cocoasamurai.blogspot.com/2008/08/xcode-shortcuts-original-documents-now.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/01/28/xcode-keyboard-shortcuts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
