<?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>shanecrawford.org &#187; Mac</title>
	<atom:link href="http://shanecrawford.org/category/mac/feed/" rel="self" type="application/rss+xml" />
	<link>http://shanecrawford.org</link>
	<description>Home Grown in Austin</description>
	<lastBuildDate>Thu, 09 Apr 2009 12:40:14 +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>Sizing a UIView in Interface Builder</title>
		<link>http://shanecrawford.org/2009/95/sizing-a-uiview-in-interface-builder/</link>
		<comments>http://shanecrawford.org/2009/95/sizing-a-uiview-in-interface-builder/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 18:24:29 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/?p=95</guid>
		<description><![CDATA[Interface Builder has come a long way since the early days of the iPhone SDK, a long way. However, there are still minor little anoyances that seem to creep up a little more often than I would like. One such anoyance that I recently uncovered was setting a custom size to a UIView when that [...]]]></description>
			<content:encoded><![CDATA[<p>Interface Builder has come a long way since the early days of the iPhone SDK, a <em>long</em> way. However, there are still minor little anoyances that seem to creep up a little more often than I would like. One such anoyance that I recently uncovered was setting a custom size to a UIView when that view is associated with a UIViewController (a very common occurance).</p>
<p>In most cases a UIView is as large as the iPhone screen or smaller. But, in a few cases you may want a view that is larger than the normal iPhone screen size. Such a case might be when using the view within a UIScrollView which is a view that can manage subviews of arbitrary size. Interface Builder makes it exceedingly easy to configure views in the majority of cases but in special cases it falls flat and specifically in the case of the views size. The issue arises when a UIView is associated directly to a UIViewController.</p>
<p><img class="aligncenter size-full wp-image-100" title="view_as_controller_subview" src="http://shanecrawford.org/blog/wp-content/uploads/2009/02/view_as_controller_subview.png" alt="view_as_controller_subview" width="425" height="134" /></p>
<p>As you can see from the screenshot the view labeled &#8216;SampleView&#8217; is shown in IB as a subview to a view controller. Interface Builder seems to like to treat a UIViewController as some sort of pseudo view which can contain subviews. This is fine from a conceptual standpoint but this pseudo view has no controlls for size, location, etc. What ends up happening is that the views size is locked into a maximum size of 320 x 480. Again this is fine for most cases but falls short for those times when you want a view larger than is standard. What&#8217;s worse is that the Inspector for a UIView will allow you that change the width and height of a view attached in this way but in reality it is limited. You can see this when running your application. This behavior also makes it impossible to design anything but the top 480 pixels of your view in Interface Builder since it will only display a view design window that is fixed to what it thinks is the maximum size. In short attaching a view as a direct &#8217;subview&#8217; of a view controller in Interface Builder can lead to some major limitations.</p>
<p>The solution to all of this is actually quite simple. Simply do not add your view as a subview to the view controllers &#8216;pseudo view&#8217;. Instead add your view as a standalone view in your NIB.</p>
<p><img class="aligncenter size-full wp-image-102" title="view_as_standalone" src="http://shanecrawford.org/blog/wp-content/uploads/2009/02/view_as_standalone.png" alt="view_as_standalone" width="429" height="276" /></p>
<p>As you can see from the second screenshot my view is not listed as a subview of the view controller but rather as a standalone view in its own right. You can then associate your custom view with the &#8216;view&#8217; outlet of the controller. Now, your view can be resized to any size that you want, you can design the entire view in IB, and it will show up with the correct size when you run your app.</p>
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2009/95/sizing-a-uiview-in-interface-builder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hasta la vista iPhone NDA</title>
		<link>http://shanecrawford.org/2008/89/hasta-la-vista-iphone-nda/</link>
		<comments>http://shanecrawford.org/2008/89/hasta-la-vista-iphone-nda/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 17:14:51 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/?p=89</guid>
		<description><![CDATA[It looks like the much loved iPhone NDA has been lifted for released iPhone software. Apple has posted a note on the iPhone developer website to that effect.
&#8220;However, the NDA has created too much of a burden on developers, authors and others interested in helping further the iPhone’s success, so we are dropping it for [...]]]></description>
			<content:encoded><![CDATA[<p>It looks like the much loved iPhone NDA has been lifted for released iPhone software. Apple has posted a <a href="http://developer.apple.com/iphone/program/">note</a> on the iPhone developer website to that effect.</p>
<p style="text-align: center;"><em>&#8220;However, the NDA has created too much of a burden on developers, authors and others interested in helping further the iPhone’s success, so we are dropping it for released software.&#8221;</em></p>
<p style="text-align: left;">Since I have been mainly focusing on iPhone development for the past few months my posts of Cocoa related development have fallen off. Now that it appears that we can write about released portions of the iPhone SDK I hope to be writing more about Cocoa Touch and of course Cocoa. I truly hope that the lifting of the NDA will help to build the iPhone developer community along a path parallel to that of the Mac developer community. I think that a golden opportunity has been missed to create the same sort of Mac developer goodwill and attitude in the iPhone developer community because of the NDA. Hopefully, now that developers are free to discuss the platform a rich and vibrant developer community will form with the same dedication to helping each other out.</p>
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2008/89/hasta-la-vista-iphone-nda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WWDC 2008 Debrief</title>
		<link>http://shanecrawford.org/2008/82/wwdc-2008-debrief/</link>
		<comments>http://shanecrawford.org/2008/82/wwdc-2008-debrief/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 15:39:16 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/?p=82</guid>
		<description><![CDATA[Another WWDC has entered the history books and I think that it was a pretty good one. As in previous WWDC&#8217;s that I&#8217;ve attended I spent the week in simultaneous states of total euphoria and near exhaustion. Unfortunately, I was unable to arrive early enough on Sunday to check-in or attend the MacSB party. The [...]]]></description>
			<content:encoded><![CDATA[<p>Another WWDC has entered the history books and I think that it was a pretty good one. As in previous WWDC&#8217;s that I&#8217;ve attended I spent the week in simultaneous states of total euphoria and near exhaustion. Unfortunately, I was unable to arrive early enough on Sunday to check-in or attend the MacSB party. The checking in part was no big deal since you can peal out of the line on Monday morning on your way into Moscone long enough to grab your badge, conference t-shirt, and laptop bag. However, missing the MacSB party hit me hard since there are a lot of people that I&#8217;d still love to hook up with and now not knowing their faces made it impossible to search for them in a crowd of over 5000 people.</p>
<p>This year for the keynote I stepped into line outside of Moscone at 5:30 am. As fortune or fate would have it I was just barely ahead of the same place in line last year when I had arrived at around 7:00 am. So, maybe that could be used as some sort of judgment on the size and enthusiasm of the crowd this year.</p>
<p style="text-align: center;"><img src="http://farm4.static.flickr.com/3108/2580923880_aeb3ba6e07.jpg" alt="" width="375" height="500" /></p>
<p>Why get in line so early and would I do that again? Yep, I think I would. Just being able to get up somewhat close to the stage for the big event makes it that much more exciting. Even more than that though you have some fun and make some friends as the line compresses and expands exposing you to different groups of people. If none of that matters to you though you can show up an hour or less prior to the keynote and watch it from one of the overflow rooms.</p>
<p>Unfortunately I can&#8217;t talk about the content of any of the WWDC sessions that I attended. However, I will say that, for me at least, most of the content seemed to be either way too high level (getting started) or way too low level (audio API&#8217;s). In any case, good info is there to be had and I picked up a lot of tips and got exposure to parts of the platform that I haven&#8217;t touched yet. Amazingly at every WWDC I have attended the speakers are first rate. They&#8217;re developers, managers, evangelists, and the like and I must say they <strong>all</strong> do an excellent job at presenting.</p>
<p>I spent a lot more time this year taking advantage of the labs that were available. The labs were divided out into major platform components and each had a dedicated area of the conference floor. Within each lab experts on a particular topic would be scheduled to be on hand during a particular time slot and all that you needed to do, in most cases, was just drop by and talk with them. Bring questions, code, or design ideas and it&#8217;s a good bet that you can talk with the guy or gal who actually wrote the code for some part of the system that your interested in. That in itself is worth the price of the conference ticket in my opinion.</p>
<p>Outside of the conference sessions, labs, and lunchtime speakers there are still plenty of Apple and non-Apple sponsored events. As for non-Apple events this is where your networking comes into play. Keep your ear to the ground because every night after the normal WWDC hours the real party begins. This year I made it to the VMWare party at &#8216;The Thirsty Bear&#8217;, the Cocoa Heads meeting at the Apple store (awesome), the Austin area Cocoa Coders get together at the &#8216;W&#8217; (hi Jim!), and the Big Nerd Ranch party. Each and everyone was a lot of fun and I didn&#8217;t even scratch the surface of the events that I could have attended.</p>
<p>On the Apple sponsored events side of the coin you&#8217;ve got the ADA awards (not to be missed), Stump the Experts (which I did miss this year in preference to sleep),  and of course the Thursday night beer bash. Apple&#8217;s beer bash is the &#8216;must do&#8217; event of the week. The food and drink selection is a couple of notches above what you&#8217;ve had all week and, prior to the entertainment coming on stage, is a decent networking opportunity. I mean when you&#8217;re standing shoulder to shoulder its kinda hard not to meet the person next to you. This year the entertainment blew me away. I&#8217;ve always been a Barenaked Ladies fan and guess who stepped on stage? Yep, BNL! I was right down front just about center stage and managed to take this shot with my iPhone:</p>
<p style="text-align: center;"><img src="http://farm4.static.flickr.com/3087/2580925828_3afb47e97f.jpg" alt="" width="375" height="500" /></p>
<p>&#8230; tons of fun and the Barenaked Ladies were a blast as they talked and jibed about Apple.</p>
<p>All in all it was a great conference. I&#8217;ll definitely be back next year. Now to sleep for a few days and dream of that new code I&#8217;ll be writing.</p>
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2008/82/wwdc-2008-debrief/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>iPhone SDK Beta 6</title>
		<link>http://shanecrawford.org/2008/81/iphone-sdk-beta-6/</link>
		<comments>http://shanecrawford.org/2008/81/iphone-sdk-beta-6/#comments</comments>
		<pubDate>Thu, 29 May 2008 18:11:37 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/?p=81</guid>
		<description><![CDATA[The latest drop of the iPhone SDK has just been released and I must say that so far it rocks! I&#8217;ve had to make only minimal updates to get my iPhone apps running on this latest drop and best of all the builds seem to be blistering fast. Well, they&#8217;re pretty darn fast anyway on [...]]]></description>
			<content:encoded><![CDATA[<p>The latest drop of the iPhone SDK has just been released and I must say that so far it rocks! I&#8217;ve had to make only minimal updates to get my iPhone apps running on this latest drop and best of all the builds seem to be blistering fast. Well, they&#8217;re pretty darn fast anyway on a Mac Pro octo (8-core) but they really seem a lot (I mean <em>a lot</em>) faster than the last version. I would dig into the actual numbers but I don&#8217;t really have time for that right now.</p>
<p>I&#8217;ll be at WWDC again this year and I can&#8217;t wait. It should be a blast assuming that the sold out conference doesn&#8217;t take away from the overall experience. June is going to be one hectic month. I&#8217;ll be flying from Mexico back to Austin and then hopping on a plane 3 hours later for WWDC. A late arrival in San Fran will be followed by an early rise to sit in line for check-in and wait for the SteveNote. I&#8217;m a bit bummed that I&#8217;ll have to miss some Sunday night get togethers but <em>c&#8217;est la vie</em>. Post WWDC holds more travel as well but it&#8217;ll be more of a local nature.</p>
<p>If you&#8217;re going to be at WWDC drop me a line and maybe we can hook up for a beer or three.</p>
<p><strong>Update</strong></p>
<p>The latest <a href="http://www.macdevnet.com/index.php/shows/mdr">Mac Developer Roundtable</a> covers some really great tips if you&#8217;re attending WWDC for the first time (or even if you&#8217;re a veteran). <a href="http://www.zarrastudios.com">Marcus Zarra</a>,  <a href="http://bill.dudney.net/roller/objc/">Bill Dudney</a>, <a href="http://www.busymac.com/">John Chaffee</a> and of course <a href="http://www.macdevnet.com/">Scotty</a> all provide some excellent insight into WWDC from an attendee perspective. Highly recommended.</p>
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2008/81/iphone-sdk-beta-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Virtual Accessors in CoreData</title>
		<link>http://shanecrawford.org/2008/66/virtual-accessors-in-coredata/</link>
		<comments>http://shanecrawford.org/2008/66/virtual-accessors-in-coredata/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 21:41:15 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/?p=66</guid>
		<description><![CDATA[In order to provide the best user experience it often occurs in a UI&#8217;s design that the underlying data model doesn&#8217;t quite mirror the mental model of the end user. Naturally, as a good UI designer you want to present to the end user what they expect to see and not force upon them your [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-76" style="float: right;" title="virtual_accessors_lead2" src="http://shanecrawford.org/blog/wp-content/uploads/2008/04/virtual_accessors_lead2.png" alt="" width="150" height="163" />In order to provide the best user experience it often occurs in a UI&#8217;s design that the underlying data model doesn&#8217;t quite mirror the mental model of the end user. Naturally, as a good UI designer you want to present to the end user what they expect to see and not force upon them your underlying implementation details. Fortunately, CoreData provides a fairly simple means of bridging this gap between the real and the ideal. This bridge over troubled waters is what might be known as virtual accessor methods</p>
<p><strong><span style="text-decoration: underline;">A Means to An End</span></strong></p>
<p>One of the great things about CoreData is the ability to model your entity objects in XCode&#8217;s data modeler and automatically have access to its attributes and relationships via Objective-C 2.0 properties or the standard Key Value Coding (KVC) methods. Simply gain access to an NSManagedObject instance for your entity and away you go. This magic is pulled off by virtue of CoreData dynamically generating efficient accessor methods for the properties that you define. These internally generated methods take the form <em>primitive</em>Key (e.g. for the property &#8216;title&#8217; the method &#8216;primitiveTitle&#8217; would be generated). CoreData then effectively injects itself into the KVC mechanisms by checking for unbounded property exceptions on calls to valueForKey: and then calling its own generated &#8216;primitive&#8217; methods in turn.</p>
<p>Another very important part of the CoreData voodoo is that NSManagedObject disables automatic key value observing change notifications. In addition, the generated primitive methods do not fire these notifications for you. Therefore, it is very important for subclasses of NSManagedObject providing their own accessor method implementations to fire the relevant access and change notification methods whenever accessing entity properties. The important methods to note are:</p>
<pre name="code" class="c">- (void)willAccessValueForKey:(NSString *)key;
- (void)didAccessValueForKey:(NSString *)key;
- (void)willChangeValueForKey:(NSString *)key;
- (void)didChangeValueForKey:(NSString *)key;
</pre>
<p>Now, finally armed with knowledge of CoreData&#8217;s intimate details we can implement our own NSManagedObject accessor methods. More importantly, the properties that those accessor methods represent do not actually need to exist on the entity definition <em>and</em> we can bind to them in Interface Builder.</p>
<p><strong><span style="text-decoration: underline;">Virtually Yours</span></strong></p>
<p>In order to demonstrate this wizardry we evoke our now ubiquitous blog application example. For this incarnation we want to automatically generate a title based on a posts author and date. A dubious example to be sure but it serves our purposes.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-72" title="virtual_accessors_app2" src="http://shanecrawford.org/blog/wp-content/uploads/2008/04/virtual_accessors_app2.png" alt="" width="235" height="303" /></p>
<p>Our first order of business is to create a BlogPost entity using XCode&#8217;s data modeler. The entity will contain only two real properties, an &#8216;author&#8217; property of type String and a &#8216;postDate&#8217; property of type Date. The &#8216;title&#8217; property will be considered as virtual and will automatically be created as a custom combination of the current value of the &#8216;author&#8217; and &#8216;postDate&#8217; attributes. Next, we need to create a <img class="alignright size-full wp-image-73" style="float: right;" title="blogpost_entity" src="http://shanecrawford.org/blog/wp-content/uploads/2008/04/blogpost_entity.png" alt="" width="131" height="78" />subclass of NSManagedObject and assign that class to our entity (See <a href="http://shanecrawford.org/2008/57/coredatas-default-date-value#subclass_nsmanagedobj">CoreData&#8217;s default date value</a> for details on doing this). The primary purpose of our subclass is two fold. First, it defines accessor methods for our virtual &#8216;title&#8217; property. Second, it overrides the setter methods for &#8216;author&#8217; and &#8216;postDate&#8217; in order to notify the system that the &#8216;title&#8217; property has changed whenever one of these two properties changes. If our title property worked in reverse and was write-only there would be no need to override the author and postDate setter methods. Here&#8217;s the code:</p>
<pre name="code" class="c">@implementation BlogPostEntity

- (NSString*) title
{
    [self willAccessValueForKey:@"author"];
    [self willAccessValueForKey:@"postDate"];

    NSString *titleAuthor = [self primitiveAuthor];
    NSDate *titleDate = [self primitivePostDate];

    [self didAccessValueForKey:@"author"];
    [self didAccessValueForKey:@"postDate"];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterNoStyle];

    NSString *title = [NSString stringWithFormat:@"%@ (%@)", [dateFormatter stringFromDate:titleDate], titleAuthor];

    [dateFormatter release];

    return title;
}

- (void)setAuthor:(NSString *)newAuthor
{
    [self willChangeValueForKey:@"author"];
    [self willChangeValueForKey:@"title"];

    [self setPrimitiveAuthor:newAuthor];

    [self didChangeValueForKey:@"author"];
    [self didChangeValueForKey:@"title"];
}

- (void)setPostDate:(NSDate *)newPostDate
{
    [self willChangeValueForKey:@"postDate"];
    [self willChangeValueForKey:@"title"];

    [self setPrimitivePostDate:newPostDate];

    [self didChangeValueForKey:@"postDate"];
    [self didChangeValueForKey:@"title"];
}
@end</pre>
<p>Take particular note of the usage of <code>willAccessValueForKey:</code>, <code>didAccessValueForKey:</code>, <code>willChangeValueForKey:</code>, and <code>didChangeValueForKey:</code>. In the &#8216;title&#8217; accessor we notify the system that we will be accessing the values of the author and postDate attributes. Likewise, in the setter methods for author and postDate we notify that we will be changing the requisite property along with title (which we are in effect changing). An additional item of interest are the calls to <code>primitiveAuthor</code>, <code>primitivePostDate</code>, <code>setPrimitiveAuthor:</code>, and <code>setPrimitivePostDate:</code>. These methods are dynamically generated by NSManagedObject and therefore are not known at compile time thus producing warnings. These warnings can easily be taken care of by creating a category which defines those methods.</p>
<pre name="code" class="c">@interface BlogPostEntity (PrimitiveAccessors)
- (NSString *)primitiveAuthor;
- (void)setPrimitiveAuthor:(NSString *)newAuthor;
- (NSDate *)primitivePostDate;
- (void)setPrimitivePostDate:(NSDate *)newPostDate;
@end</pre>
<p>As you can see nowhere did we define an actual &#8216;title&#8217; property on our BlogPost entity in the data modeler. Yet, we can now bind to that property in Interface Builder and allow our interface to diverge from the underlying data model when needed.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-74" title="title_bindings" src="http://shanecrawford.org/blog/wp-content/uploads/2008/04/title_bindings.png" alt="" width="274" height="189" /></p>
<p style="text-align: left;">For those that want to take a closer look the example XCode project can be found here: <a href="http://shanecrawford.org/blog/wp-content/uploads/2008/04/virtualaccessors.dmg">Virtual Accessors Example Project</a>. For the rest, keep this little technique in mind for those occasions when you know that the user interface should be this way or that but you just don&#8217;t want to torque your data model. Code on.</p>
<p style="text-align: left;">
<p><em><strong>Update</strong></em></p>
<p><a href="http://www.theocacao.com/">Scott Stevenson</a> has provided an improvement to this technique. The end result is the same but the implementation is more elegant and much more maintainable. In essence, instead of overriding the accessor methods for author and postDate we provide an implementation for +keyPathsForValuesAffectingTitle. This lets the system know that a modification to either &#8216;author&#8217; or &#8216;postDate&#8217; should also trigger a change to &#8216;title&#8217; thus eliminating the need to override their accessor methods. Sweet. In addition, since we still need to access the values for author and postDate we go ahead and define them as Objective-C 2.0 properties of our NSManagedObject subclass with the implementation tagged as @dynamic. This prevents compiler errors while still allowing us to access the values as provided by our superclass. Very nice indeed. An updated project can be found here: <a href='http://shanecrawford.org/blog/wp-content/uploads/2008/04/virtualaccessorsimproved.dmg'>Virtual Accessors Example Project Improved</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2008/66/virtual-accessors-in-coredata/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CoreData&#8217;s default date value</title>
		<link>http://shanecrawford.org/2008/57/coredatas-default-date-value/</link>
		<comments>http://shanecrawford.org/2008/57/coredatas-default-date-value/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 02:17:10 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/2008/57/coredatas-default-date-value/</guid>
		<description><![CDATA[CoreData is a powerful system available to Cocoa developers. Yet, with all of its inherent power somewhat mundane tasks still need a bit of customization love. Amoung these items are default values for managed object attributes. In particular, the default value for date type attributes usually need some customization.
Within the core data modeler the default [...]]]></description>
			<content:encoded><![CDATA[<p>CoreData is a powerful system available to Cocoa developers. Yet, with all of its inherent power somewhat mundane tasks still need a bit of customization love. Amoung these items are default values for managed object attributes. In particular, the default value for date type attributes usually need some customization.</p>
<p>Within the core data modeler the default value for a date type attribute exists as a rather ambiguous empty text field. Documentation on what can be entered into this text field are, shall we say, rather hard to come by. With a bit of experimentation and extensive Googling it can be found that the values &#8220;now&#8217;&#8221;and &#8220;today&#8221; can be entered into the field (quotes needed).</p>
<p align="center"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/03/postentry_attribute_editor.png" alt="post entry attribute editor" /></p>
<p align="left">As expected this will automatically fill in  the current date as the default value for the attribute. However, there seems to be little difference between &#8220;now&#8221; and &#8220;today&#8221; in that the time portion of the date is always set to 12:00:00. You might expect the &#8220;today&#8221; value to work this way but it would certainly be nice if &#8220;now&#8221; truly meant &#8216;right now&#8217; and not &#8216;now more or less kinda&#8217;. But, if this will work for you then you&#8217;re done.</p>
<p align="left">If having a fixed date is what you need then you could always provide a natural language string as defined in the documentation for [NSDate dateWithNaturalLanguageString]. In fact, ALL of the following default values for a date type seem to work:</p>
<p align="center"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/03/date_format_1.png" alt="date format 1" /></p>
<p align="center"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/03/date_format_2.png" alt="date format 2" /></p>
<p align="center"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/03/date_format_3.png" alt="date format 3" /></p>
<p align="left">Yes, you read that right. Even &#8220;last Tuesday at dinner&#8221; works here:</p>
<p align="center"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/03/last_tues_dinner.png" alt="tues dinner" /></p>
<p align="left">Amazingly, we can easily get the time for last Tuesdays dinner but the current time is a mystery. Leave it up to us software developers to be focused on meals.</p>
<p align="left">In the end if you need  to set the default value of a date attribute to the current date <em>and</em> time you&#8217;ll need to subclass NSManagedObject. It&#8217;s an easy thing to do so here it is:</p>
<p><a name="subclass_nsmanagedobj"></a></p>
<p align="left">First, define a subclass of NSManagedObject. We&#8217;ll call this class &#8216;BlogEntryEntity&#8217;. Next, we need to override the NSManagedObject method &#8216;awakeFromInsert&#8217;.</p>
<pre name="code" class="c">- (void) awakeFromInsert
{
[super awakeFromInsert];
[self setValue:[NSCalendarDate date] forKey:@"postDate"];
}</pre>
<p align="left">As you can see it&#8217;s just two lines of code after overriding the method. Be sure to invoke the superclass&#8217;s method first as per the NSManagedObject docs. To make things simple we make use of NSManagedObjects excellent KVC abilities and use the setValue:forKey: method. Finally, we need to set the class of our BlogEntry  managed object. This is done by simply changing the &#8216;Class&#8217; field of the class attributes in the core data modeler from NSManagedObject to BlogEntryEntity.</p>
<p align="center"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/03/blogentryentity.png" alt="blog entry entity" /></p>
<p align="left">That&#8217;s it. Now, whenever an instance of BlogEntry is created the postDate attribute is set to the current date and time. Have fun, and let us know in the comments if you find any other interesting default values that work.</p>
<p align="left">
<p align="left">
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2008/57/coredatas-default-date-value/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Java on the iPhone? Say it ain&#8217;t so&#8230;</title>
		<link>http://shanecrawford.org/2008/56/java-on-the-iphone-say-it-aint-so/</link>
		<comments>http://shanecrawford.org/2008/56/java-on-the-iphone-say-it-aint-so/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 14:14:44 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/2008/56/java-on-the-iphone-say-it-aint-so/</guid>
		<description><![CDATA[Almost as soon as the iPhone SDK was released Sun announced its plans to develop and release the JVM for the iPhone. As a long time Java developer I should be ecstatic about this news. However, rather than causing sleepless nights dreaming about the possibilities of a JVM on the iPhone it somewhat depresses me. [...]]]></description>
			<content:encoded><![CDATA[<p>Almost as soon as the iPhone SDK was released Sun announced its plans to develop and release the JVM for the iPhone. As a long time Java developer I should be ecstatic about this news. However, rather than causing sleepless nights dreaming about the possibilities of a JVM on the iPhone it somewhat depresses me. Now, I must say that I do enjoy developing in Java and have been doing so professionally since early 1999 with code still being used in large projects ranging from Swing front ends to J2EE backends. In all fairness my J2ME experience has been little more than a hobby but I have had some fun with it.</p>
<p>So, does Java on the iPhone make sense to anyone other than a pre-supernova Sun? Mmmm&#8230; well, I&#8217;m sure that the thousands of J2ME application developers out there would be pumping for it. There might also be a few users who rely on some mission critical application. Anyone else? None spring to mind, certainly not Apple.</p>
<p>A post-apocalyptic JVM enabled iPhone would soon become a litter ground for the multitude of J2ME apps. Some of these apps, such as the ones developed by Google, are indeed beneficial and well done. They are, however, far from the norm. With Apple&#8217;s tight control over the platform any J2ME apps would surely need to be provisioned directly from the iPhone AppStore which might help to eliminate some of the cruft. But, a free for all iPhone application bonanza is not likely to happen in this universe and that includes J2ME apps.</p>
<p>As a fledgling iPhone developer I must also say that a massive influx of J2ME apps to the iPhone would severly dampen my enthusiasm for the platform. All those J2ME apps would immediately have first mover advantage in a lot of important application categories &#8211; thus castrating many native iPhone applications. One of the draws to iPhone development is that it is a green field&#8230; there are thousands upon thousands of apps that need developing and for the uninitiated that spells &#8220;opportunity&#8221;.</p>
<p>Java on the iPhone proponents see the iPhone as another smart phone market for J2ME applications. However, the iPhone is much more than just a smart phone. It&#8217;s a completely new platform and more than any other device that has come before it is a powerful computer in your pocket. In order to make full use of all that the device offers only native code can deliver. Witness this quote from <span class="artText">Eric Klein, vice president of Java marketing at Sun</span> (source <a href="http://arstechnica.com/journals/apple.ars/2008/03/08/java-for-iphone-coming-soon">ars technica</a>),</p>
<blockquote><p><em>&#8220;We&#8217;re going to make sure that the JVM offers the Java applications as much access to the native functionality of the iPhone as possible,&#8221; he said. </em></p></blockquote>
<p>Why would we even settle for anything less than complete access to the native iPhone functionality? Do some J2ME apps not need all that the iPhone has to offer? Well, then they aren&#8217;t iPhone apps and users will know the difference.</p>
<p>So, why throw my  vote towards native Objective-C iPhone apps rather than building on my already deep Java knowledge and J2ME? It&#8217;s simple. Hands down the best user experience will be had by witting applications which make use of the unique and powerful native iPhone API&#8217;s. As a developer with a user experience mindset I only want the best and adding J2ME to the mix only waters it down.</p>
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2008/56/java-on-the-iphone-say-it-aint-so/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone SDK first impressions</title>
		<link>http://shanecrawford.org/2008/53/iphone-sdk-first-impressions/</link>
		<comments>http://shanecrawford.org/2008/53/iphone-sdk-first-impressions/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 19:22:46 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/2008/53/iphone-sdk-first-impressions/</guid>
		<description><![CDATA[Unless you&#8217;ve been living under a rock for the past week you&#8217;ve probably heard  about the new iPhone SDK beta release by Apple. The SDK opens the doors to what promises to be a groundbreaking platform for software development. In fact, legendary VC firm KPCB believes in the platforms possibilities so much that they [...]]]></description>
			<content:encoded><![CDATA[<p align="left"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/03/08iphone_front.png" align="right" alt="iPhone stock image" />Unless you&#8217;ve been living under a rock for the past week you&#8217;ve probably heard  about the new iPhone SDK beta release by Apple. The SDK opens the doors to what promises to be a groundbreaking platform for software development. In fact, legendary VC firm KPCB believes in the platforms possibilities so much that they have set up a $100M investment fund in order fuel the flames of innovation. It&#8217;ll be interesting to see what comes out of the <a href="http://www.kpcb.com/initiatives/ifund/index.html">iFund</a>.</p>
<p align="left">Even though developers like myself have been drinking in the SDK for the past several days Apple has silenced open discussion of the SDK via an NDA (required to get the SDK). Hopefully, this restriction will be lifted once the SDK goes public near the end of June so that we can dig into some meaty code details. One thing that I will say is that it appears that Apple has really put a lot of work into producing the SDK. The documentation on the <a href="http://developer.apple.com/iphone">iPhone Dev Center</a> is excellent and hints at a well planned out release.</p>
<p align="left">There has been a lot of discussion surrounding the new AppStore and the 70/30 split Apple is making with developers. On the surface the developer deal sounds great and a 70/30 split with Apple taking care of hosting, processing fees, and a lot of the marketing seems fair assuming that millions of potential users get exposed to an app. However, as they say, the devil is in the details and we have a lot of details yet to flesh out. I&#8217;ll reserve my final judgment to the time when the SDK and the developer program go public and we&#8217;ve had a few months to see how  it all works out. Until then I remain cautiously optimistic about the business deal and ecstatic about a cool new platform to develop software for.</p>
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2008/53/iphone-sdk-first-impressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Warning about your inverse relationships</title>
		<link>http://shanecrawford.org/2008/49/a-warning-about-your-inverse-relationships/</link>
		<comments>http://shanecrawford.org/2008/49/a-warning-about-your-inverse-relationships/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 02:21:33 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/2008/49/a-warning-about-your-inverse-relationships/</guid>
		<description><![CDATA[When working on a data model it is common to run into a situation where one data entity knows about another but not the other way around. Usually you can make the argument that both objects should know about each other. However, for one reason or another, which usually comes down to some underlying implementation [...]]]></description>
			<content:encoded><![CDATA[<p>When working on a data model it is common to run into a situation where one data entity knows about another but not the other way around. Usually you can make the argument that both objects should know about each other. However, for one reason or another, which usually comes down to some underlying implementation detail or design decision, you may have a need for a one way relationship. For example, if I&#8217;m creating a blogging application (which I&#8217;m not) I might decide that a Blog entity knows about all of its associated BlogPosts but there is no need for blog posts to know about the blog that they live in (an application specific design decision). This would give rise to the following data model:
<p style="text-align: center"> <img src="http://shanecrawford.org/blog/wp-content/uploads/2008/02/blog_model.png" alt="blog and post model" /></p>
<p style="text-align: left">As you can see our &#8216;Blog&#8217; entity knows about multiple &#8216;BlogPost&#8217; entities but not the other way around. XCode refers to these other relationships as the &#8216;inverse relationship&#8217;. So, for our simple example there is no inverse relationship between BlogPost and Blog.</p>
<p style="text-align: left">&#8220;Well, ok, so what&#8217;s the big deal?&#8221;, you may be thinking. The big deal is Warnings my friend. If you&#8217;re like me you like your code to compile without a bunch of warnings. That way when something does come up it is easily spotted. It seems that Apple really, really wants you to have those inverse relationships. In fact, they pretty much say so in the <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/CoreData.pdf">Core Data documentation</a>: </p>
<blockquote style="text-align: center; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-width: initial; border-color: initial; border-style: none; padding: 0px" class="webkit-indent-blockquote"><p><span style="font-style: italic" class="Apple-style-span">&#8220;It is possible for relationships to be navigable in only one direction (if you are never interested in finding out from a department object what employees are associated with it, then you do not have to model that relationship), however you are strongly encouraged always to model relationships in both directions.&#8221; </span></p></blockquote>
<p>In fact, Apple feels so strongly about this that your build will produce a warning for each relationship that does not have an inverse.
<p style="text-align: center"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/02/inverse_warnings.png" alt="no inverse relationship warnings" /></p>
<p style="text-align: left">So much for my clean build. Or is it? A little digging reveals that the kind hearted folks at Apple thought ahead and created a build setting to turn these warnings off if you so desire. Note that they are on by default. Simply open up the build settings for your project in XCode and search for &#8216;momc&#8217;. The utility momc is the XCode model compiler which can also be run from the command line if needed (see the <a href="http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeUserGuide/Contents/Resources/en.lproj/02_40_design_data_modeling/chapter_17_section_8.html">XCode User Guide</a> for more info)</p>
<p style="text-align: center"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/02/momc_build_settings.png" alt="momc build settings" /></p>
<p style="text-align: left">Simply check the box to &#8216;Suppress momc warnings on missing inverse relationships&#8217; and you&#8217;re done. No more warnings on a data model that you know is the way you want it. How thoughtful. Props to the guy (or gal) who fought for  this setting!</p>
<p><br class="webkit-block-placeholder" /></p>
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2008/49/a-warning-about-your-inverse-relationships/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Action PopUp Button in Leopard</title>
		<link>http://shanecrawford.org/2008/41/creating-an-action-popup-button-in-leopard/</link>
		<comments>http://shanecrawford.org/2008/41/creating-an-action-popup-button-in-leopard/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 18:04:46 +0000</pubDate>
		<dc:creator>shane</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://shanecrawford.org/2008/41/creating-an-action-popup-button-in-leopard/</guid>
		<description><![CDATA[It seems that everywhere you look in OS X you see applications with popup action buttons. You know,  that  button with a gear on it. Click it and a menu full of goodies pops up for you to play with. Apple itself uses it pretty extensively in its apps; Mail and Finder are [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/02/lead_action_button.png" alt="lead action button" align="left" />It seems that everywhere you look in OS X you see applications with popup action buttons. You know,  that  button with a gear on it. Click it and a menu full of goodies pops up for you to play with. Apple itself uses it pretty extensively in its apps; Mail and Finder are notable examples. With such a prevalent control you would think it was dirt simple to create on of these for your own application. You&#8217;d think, but prior to Leopard you&#8217;d be wrong (mostly). A quick search around the web shows that there has been much <a href="http://www.cocoadev.com/index.pl?HowToMakeAnActionButton">discussion</a> on the topic with quite a few various implementations. In fact, you may have googled your way here in search of a solution. Read on and I think you&#8217;ll be pleasantly surprised.</p>
<p align="left">The essence of most implementations for an action button rely on NSPopUpButton and this implementation is no different.  Where things start to diverge is that this implementation can be completed entirely within Interface Builder &#8211; no subclassing or custom rendering needed. So let&#8217;s get started and we&#8217;ll crank out this puppy.</p>
<p align="left">NSPopUpButton operates in two different major modes which are &#8216;Pop Up&#8217; and &#8216;Pull Down&#8217;. For this implementation we&#8217;ll be relying on the &#8216;Pull Down&#8217; behavior which gives us a button with the requisite down arrow. So, just drag an NSPopUpButton onto your application in the desired location, choose &#8216;Pull Down&#8217; from the inspector, choose the arrow to be along the bottom edge, and ensure that the &#8216;Title&#8217; attribute is empty. Following is a thumbnail of the full inspector for a properly configured NSPopUpButton (click to enlarge).</p>
<p align="center"><a href="http://shanecrawford.org/blog/wp-content/uploads/2008/02/inspector_attributes.png" title="NSPopUpButton Attributes Inspector"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/02/inspector_attributes.thumbnail.png" alt="NSPopUpButton Attributes Inspector" /></a></p>
<p align="left"> You should now have a popup button with a blank title area and a down arrow. Sizing of the button is a hit-or-miss exercise and is probably the biggest drawback of this technique. As you will see even though <img src="http://shanecrawford.org/blog/wp-content/uploads/2008/02/ib_action_button.png" alt="ib action button" align="right" />we will have the gear icon in the built application we will not see it rendered in Interface Builder. The next major step is hooking up the menu that we will use. By default NSPopUpButton comes with a menu that has three items in it. For whatever reason if you try to modify this menu by adding new items things start to get out of control. So, we just bypass the default provided menu and create our own. When in &#8216;Pull Down&#8217; mode NSPopUpButton utilizes the first NSMenuItem in the menu as the title for the button. Herein lies the trick that makes the whole thing work.</p>
<p align="left">To start off this phase of the button development drag an NSMenu from the Interface Builder pallet  into your NIB file. Name it something exciting like &#8216;ActionMenu&#8217; in order to distinguish it from other menus in your NIB (you can do this via the &#8216;Identity&#8217; tab in the inspector &#8211; see the Interface Builder Identity &#8216;Name&#8217; attribute). Next build up your menu as desired reserving the very first menu item for our popup button custom use. You can connect your menu items to Actions in your code as needed (the blank menu takes no action &#8211; its used only by NSPopUpButton). Now, in order to get our gear icon to show up on our popup button we need to configure the attributes of that very first menu item. The key is to configure the menu item to have a blank title and to set the &#8216;Image&#8217; attribute to have the value &#8216;NSActionTemplate&#8217; (you will need to type NSActionTemplate into the text field).</p>
<p align="center"><img src="http://shanecrawford.org/blog/wp-content/uploads/2008/02/menu_item_attributes.png" alt="menu item attributes" /></p>
<p align="left">The value NSActionTemplate sets the image of the menu item to be the gear icon. This comes from the new Media Library in Interface Builder 3. To see this for yourself bring up the media library, find the gear icon and click on it. You will see that its name is NSActionTemplate.</p>
<p align="left"> <img src="http://shanecrawford.org/blog/wp-content/uploads/2008/02/menuitem_attributes.png" alt="menuitem attribs" align="right" /><br />
Now for the final connection. To bring the menu and the popup button together find your popup button and bring up its inspector. Connect its menu outlet to your NSMenu. That&#8217;s pretty much it. You&#8217;ll probably need to play with the actual size of the button (sans image) in order to get things to look right when you build and run the application. You can also play with some of the NSPopUpButton attributes to control the default location that the menu popups up at etc. However, you now have the often desired action popup button without any subclassing or custom rendering. Enjoy.</p>
<p align="left">&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://shanecrawford.org/2008/41/creating-an-action-popup-button-in-leopard/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
