<?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>Mike Fullerton&#039;s blog &#187; Uncategorized</title>
	<atom:link href="http://blog.mikefullerton.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mikefullerton.com</link>
	<description>yet another iOS developer</description>
	<lastBuildDate>Thu, 18 Aug 2011 02:40:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Rowwwr!</title>
		<link>http://blog.mikefullerton.com/2011/08/17/rowwwr/</link>
		<comments>http://blog.mikefullerton.com/2011/08/17/rowwwr/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 02:40:08 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mikefullerton.com/2011/08/17/rowwwr/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p></p><div class='posterous_autopost'><a href="http://instagr.am/p/KhkR_/">
<div class='p_embed p_image_embed'> <a href="http://posterous.com/getfile/files.posterous.com/mikefullerton/wAFggasruluIezFlAtFrpclunmaCpAwbzDmuinqmqdetadjceGcFqChgfcHs/media_httpimagesinsta_smgon.jpg.scaled1000.jpg"><img alt="Media_httpimagesinsta_smgon" height="500" src="http://posterous.com/getfile/files.posterous.com/mikefullerton/wAFggasruluIezFlAtFrpclunmaCpAwbzDmuinqmqdetadjceGcFqChgfcHs/media_httpimagesinsta_smgon.jpg.scaled500.jpg" width="500" /></a> </div>
<p> </a></div>
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2011/08/17/rowwwr/" data-counturl="http://blog.mikefullerton.com/2011/08/17/rowwwr/" data-text="Rowwwr!" class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F17%2Frowwwr%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2011/08/17/rowwwr/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F17%2Frowwwr%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2011/08/17/rowwwr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coffee time</title>
		<link>http://blog.mikefullerton.com/2011/08/17/coffee-time/</link>
		<comments>http://blog.mikefullerton.com/2011/08/17/coffee-time/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 01:57:53 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mikefullerton.com/2011/08/17/coffee-time/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p></p><div class='posterous_autopost'><a href="http://instagr.am/p/Kjd4x/">
<div class='p_embed p_image_embed'> <a href="http://posterous.com/getfile/files.posterous.com/mikefullerton/rhwsscJBGpvEhFouwxplGAJayhixIttAuajvJHHrIBjjJswpjjfpxxfuHDdz/media_httpimagesinsta_lDjnE.jpg.scaled1000.jpg"><img alt="Media_httpimagesinsta_ldjne" height="500" src="http://posterous.com/getfile/files.posterous.com/mikefullerton/rhwsscJBGpvEhFouwxplGAJayhixIttAuajvJHHrIBjjJswpjjfpxxfuHDdz/media_httpimagesinsta_lDjnE.jpg.scaled500.jpg" width="500" /></a> </div>
<p> </a></div>
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2011/08/17/coffee-time/" data-counturl="http://blog.mikefullerton.com/2011/08/17/coffee-time/" data-text="Coffee time" class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F17%2Fcoffee-time%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2011/08/17/coffee-time/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F17%2Fcoffee-time%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2011/08/17/coffee-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sleeping</title>
		<link>http://blog.mikefullerton.com/2011/08/13/sleeping/</link>
		<comments>http://blog.mikefullerton.com/2011/08/13/sleeping/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 04:58:46 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mikefullerton.com/2011/08/13/sleeping/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p></p><div class='posterous_autopost'><a href="http://instagr.am/p/KM_28/">
<div class='p_embed p_image_embed'> <a href="http://posterous.com/getfile/files.posterous.com/mikefullerton/mfIujxwIJkodbtmqIssHEHjzGdujICvomnGjBpDrxiDgiFkGuqwJuvlABCDs/media_httpimagesinsta_wzCfC.jpg.scaled1000.jpg"><img alt="Media_httpimagesinsta_wzcfc" height="500" src="http://posterous.com/getfile/files.posterous.com/mikefullerton/mfIujxwIJkodbtmqIssHEHjzGdujICvomnGjBpDrxiDgiFkGuqwJuvlABCDs/media_httpimagesinsta_wzCfC.jpg.scaled500.jpg" width="500" /></a> </div>
<p> </a></div>
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2011/08/13/sleeping/" data-counturl="http://blog.mikefullerton.com/2011/08/13/sleeping/" data-text="Sleeping" class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F13%2Fsleeping%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2011/08/13/sleeping/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F13%2Fsleeping%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2011/08/13/sleeping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sanjo</title>
		<link>http://blog.mikefullerton.com/2011/08/13/sanjo-4/</link>
		<comments>http://blog.mikefullerton.com/2011/08/13/sanjo-4/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 03:55:52 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mikefullerton.com/2011/08/13/sanjo-4/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p></p><div class='posterous_autopost'><a href="http://instagr.am/p/KMpAu/">
<div class='p_embed p_image_embed'> <a href="http://posterous.com/getfile/files.posterous.com/mikefullerton/uggkqilIhcyDrEvcikjdrjuFDtBynfzeiCtqjwlArkehIAftawwHdlxDpwsJ/media_httpimagesinsta_HkqjF.jpg.scaled1000.jpg"><img alt="Media_httpimagesinsta_hkqjf" height="500" src="http://posterous.com/getfile/files.posterous.com/mikefullerton/uggkqilIhcyDrEvcikjdrjuFDtBynfzeiCtqjwlArkehIAftawwHdlxDpwsJ/media_httpimagesinsta_HkqjF.jpg.scaled500.jpg" width="500" /></a> </div>
<p> </a></div>
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2011/08/13/sanjo-4/" data-counturl="http://blog.mikefullerton.com/2011/08/13/sanjo-4/" data-text="Sanjo" class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F13%2Fsanjo-4%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2011/08/13/sanjo-4/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F13%2Fsanjo-4%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2011/08/13/sanjo-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sanjo</title>
		<link>http://blog.mikefullerton.com/2011/08/13/sanjo-3/</link>
		<comments>http://blog.mikefullerton.com/2011/08/13/sanjo-3/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 03:55:45 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mikefullerton.com/2011/08/13/sanjo-3/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p></p><div class='posterous_autopost'><a href="http://instagr.am/p/KMpAu/">
<div class='p_embed p_image_embed'> <a href="http://posterous.com/getfile/files.posterous.com/mikefullerton/xugdDzsiaJchiJxGFvIwmFmpCeACzeyyIxCwepwJJFpvjBldlGDuAbzDCiGi/media_httpimagesinsta_jrsue.jpg.scaled1000.jpg"><img alt="Media_httpimagesinsta_jrsue" height="500" src="http://posterous.com/getfile/files.posterous.com/mikefullerton/xugdDzsiaJchiJxGFvIwmFmpCeACzeyyIxCwepwJJFpvjBldlGDuAbzDCiGi/media_httpimagesinsta_jrsue.jpg.scaled500.jpg" width="500" /></a> </div>
<p> </a></div>
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2011/08/13/sanjo-3/" data-counturl="http://blog.mikefullerton.com/2011/08/13/sanjo-3/" data-text="Sanjo" class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F13%2Fsanjo-3%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2011/08/13/sanjo-3/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F13%2Fsanjo-3%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2011/08/13/sanjo-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Untitled</title>
		<link>http://blog.mikefullerton.com/2011/08/13/untitled/</link>
		<comments>http://blog.mikefullerton.com/2011/08/13/untitled/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 03:41:57 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mikefullerton.com/2011/08/13/untitled/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p></p><div class='posterous_autopost'><a href="http://instagr.am/p/KMkqx/">
<div class='p_embed p_image_embed'> <a href="http://posterous.com/getfile/files.posterous.com/mikefullerton/arJemHljJqBnqwoogAolodCntxkdHEgdnelhDjDvebiGunsBmabtIblgrouI/media_httpimagesinsta_dlHFj.jpg.scaled1000.jpg"><img alt="Media_httpimagesinsta_dlhfj" height="500" src="http://posterous.com/getfile/files.posterous.com/mikefullerton/arJemHljJqBnqwoogAolodCntxkdHEgdnelhDjDvebiGunsBmabtIblgrouI/media_httpimagesinsta_dlHFj.jpg.scaled500.jpg" width="500" /></a> </div>
<p> </a></div>
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2011/08/13/untitled/" data-counturl="http://blog.mikefullerton.com/2011/08/13/untitled/" data-text="Untitled" class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F13%2Funtitled%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2011/08/13/untitled/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F08%2F13%2Funtitled%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2011/08/13/untitled/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>a pattern for initializing objective-c objects with blocks</title>
		<link>http://blog.mikefullerton.com/2011/07/27/a-pattern-for-initializing-objective-c-objects-with-blocks/</link>
		<comments>http://blog.mikefullerton.com/2011/07/27/a-pattern-for-initializing-objective-c-objects-with-blocks/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 01:26:06 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mikefullerton.com/?p=1708</guid>
		<description><![CDATA[First off, this is kind of a warm up post. I&#8217;m struggling with figuring how to post source code into my post without killing chickens and using their blood for magic rituals. I&#8217;ll probably screw it up. It may be also that I need to elaborate on stuff here &#8211; I&#8217;m a bit rusty with [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>First off, this is kind of a warm up post. I&#8217;m struggling with figuring how to post source code into my post without killing chickens and using their blood for magic rituals. I&#8217;ll probably screw it up. It may be also that I need to elaborate on stuff here &#8211; I&#8217;m a bit rusty with the technical writing. So please don&#8217;t hesitate to ask questions or ask for more info. Or if you have a better idea about something I&#8217;m writing about, or I have it wrong, or I have spinach in my teeth, please let me know.</p>
<p>To get the most out of this post you should understand <a href="http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html">objective-c blocks</a>, and <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocCategories.html#//apple_ref/doc/uid/TP30001163-CH20-SW1">objective-c categories</a>.</p>
<p>Ok, warp factor one. Engage.</p>
<p>This is a useful pattern I&#8217;ve discovered after playing with it in various incarnations since iOS 4 came out. I&#8217;ve landed on a design which is super simple, and really easy to use. The example&#8217;s here are silly and contrived, but the pattern works at scale with large shipping code.</p>
<p>I&#8217;m a big fan of objective-c blocks. I first learned about them when using Javascript closures at Microsoft and they <em>blew</em> my mind back then. Now, not so much with the mind blowing, but they&#8217;re very useful and I was super excited when they came to objective-c. They have their dangers and drawbacks (which I&#8217;ll explore in another post), but for this, they&#8217;re <em>perfect</em> because you can use them inline with your normal code &#8211; you don&#8217;t have to declare extra functions or methods or whatever for fancy or complex initializaton.</p>
<p>Let me explain.</p>
<p>Here&#8217;s the situation. You need to build a list of objects that <em>do</em> something, or <em>represent</em> something. For example, this might be a list of addresses, or a queue of tasks to perform, or whatever. We do this all the time. For this, we need to configure a bunch of ducks. Funky ducks.</p>
<p>Let&#8217;s start with an example.</p>
<p>I need to create 3 GtFunkyDuck objects and add them to a NSMutableArray.</p>
<p>(Note that GtFunkyDuck isn&#8217;t a real object, and the properties and method names will just be silliness to illustrate my point. Also, my company is <a href="http://www.greentongue.com">GreenTongue Software</a>, so all my objects are prefixed with &#8220;Gt&#8221;. You know, it stands for Goober Tooth or Grand Teton or Got Tamatoes&#8230;).</p>
<p>Here&#8217;s the normal way to initialize some ducks. Hmm, did I really just write that?</p>
<pre class="brush: objc; title: ; notranslate">
NSMutableArray* myArray = [NSMutableArray array];

GtFunkyDuck* myDuck1 = [[[GtFunkyDuck alloc] init] autorelease];
myDuck1.feetAreWebbed = YES;
myDuck1.billColor = [UIColor redColor];
myDuck1.quackVolume = 6;
[myDuck1 getReadyToSwimInPond:myPond];
[myArray addObject:myDuck1];

GtFunkyDuck* myDuck2 = [[[GtFunkyDuck alloc] init] autorelease];
myDuck2.feetAreWebbed = NO;
myDuck2.billColor = [UIColor greenColor];
myDuck2.quackVolume = 1;
[myDuck1 getReadyToSwimInBathtub:aBathtub];
[myArray addObject:myDuck2];

GtFunkyDuck* myDuck3 = [[[GtFunkyDuck alloc] init] autorelease];
myDuck1.feetAreWebbed = NO;
myDuck3.billColor = [UIColor blueColor];
myDuck3.quackVolume = 2;
[myDuck1 getReadyToChaseAToddler:aToddler];
[myArray addObject:myDuck1];
</pre>
<p>This post illustrates what I&#8217;m talking about very well. Look closely. There are a couple of bugs here. Why? Because I&#8217;m lazy and I copied and pasted myDuck1 to reuse the code for myDuck2 and myDuck3. I want this code written, now, I can&#8217;t be bothered retyping GtFunkyDuck seventy-hundred times. So copy-paste here I come, and then I got distracted by twitter and screwed up myDuck3. This could cause weirdass bugs that are hard to track down. myDuck1 was added twice to the array, myDuck3 was never added, and myDuck1 doesn&#8217;t have webbedFeet like it&#8217;s supposed to. Well, you get the idea. It&#8217;s far <em>easier</em> to screw up the code here than to get it right, in my experience. Copy and paste. Deliciously dangerous.</p>
<p>One solution is to add an initWithWebbedFeet method and have a bunch of parameters for building the object. But what if the object has twentysix options? Or complex configuration methods? What if the default initializer puts the object into a state that&#8217;s just fine? If so, there&#8217;s no point in passing in all the parameters, or creating six quadrillion different init methods, and in fact that will make the code very difficult to maintain and debug</p>
<pre class="brush: objc; title: ; notranslate">
GtFunkyDuck* myDuck1 = [[[GtFunkyDuck alloc] initWithWebbedFeet:YES billColor:[UIColor redColor] quackVolume:4 swimsInCircles:NO likesBreadCrusts:YES hatesChickens:YES chasesSmallChildren:NO willBeATastyMealSomeday:YES] autorelease];
</pre>
<p>This is just damn painful. In my experience, if there are more than two or three parameters, you&#8217;re in for some hurt. Big fat painful hurt, deep in the debugger, complete with dog kicking cursing and heavy drinking. Well, maybe not that bad. And for the record, I never kicked my dog. (Or your dog).</p>
<p>So there are two problems here:</p>
<ol>
<li>We have to create a bunch of local variables to hold temporary references to the objects we&#8217;re creating, e.g. myDuck1, myDuck2, and myDuck3. This gets painful and buggy, after, well, one, because everyone copies and pastes and we forget or miss changing the names in the newly pasted code in our hurry to implement our new duck related feature.</li>
<li>We have complex objects with a bunch of optional parameters. These damn ducks are high maintainence. They have a lot of options.</li>
</ol>
<p>Here&#8217;s my simple solution:</p>
<pre class="brush: objc; title: ; notranslate">

typedef void (^GtConfigureObjectBlock)(id object);

@interface NSMutableArray (GtArrayAdditions)
- (void) addObject:(id) object configureObject:(GtConfigureObjectBlock) block;
@end

@implementation NSMutableArray (GtArrayAdditions)
- (void) addObject:(id) object configureObject:(GtConfigureObjectBlock) block {
    if(block){
        block(object);
    }
    [self addObject:object];
}
@end
</pre>
<p>What we&#8217;re doing here is passing in a object in a default state, and then modifying that default state with your block callback. This elimates all the local variables and nearly all the opportunity for cut and paste errors, which can be traced back to having to reference the objects through their local variables. So our new fancy code for initializing our ducks looks like this now:</p>
<pre class="brush: objc; title: ; notranslate">
NSMutableArray* myArray = [NSMutableArray array];

[myArray addObject:[[[GtFunkyDuck alloc] init] autorelease] configureObject:^(id duck) {
    [duck setFeetAreWebbed:YES];
    [duck setBillColor:[UIColor redColor]];
    [duck setQuackVolume:6];
    [duck getReadyToSwimInPond:myPond];
}];
[myArray addObject:[[[GtFunkyDuck alloc] init] autorelease] configureObject:^(id duck) {
    [duck setFeetAreWebbed:NO];
    [duck setBillColor:[UIColor greenColor]];
    [duck setQuackVolume:1];
    [duck getReadyToSwimInBathtub:aBathtub];
}];
[myArray addObject:[[[GtFunkyDuck alloc] init] autorelease] configureObject:^(id duck) {
    [duck setFeetAreWebbed:NO];
    [duck setBillColor:[UIColor blueColor]];
    [duck setQuackVolume:2];
    [duck getReadyToChaseAToddler:aToddler];
}];
</pre>
<p>The only draw back is that you loose the ability to use the properties. You can&#8217;t do this:</p>
<pre class="brush: objc; title: ; notranslate">
[myArray addObject:[[[GtFunkyDuck alloc] init] autorelease] configureObject:^(id duck) {
duck.feetAreWebbed = NO;
}];
</pre>
<p>You also can&#8217;t do this (unfortunately):</p>
<pre class="brush: objc; title: ; notranslate">
[myArray addObject:[[[GtFunkyDuck alloc] init] autorelease] configureObject:^(GtFunkyDuck* duck) {
duck.feetAreWebbed = NO;
}];
</pre>
<p>However, I view the inability here to use the properties as merely cosmetic. The trade off in better code and less bugs is worth it.</p>
<p>This may look a little weird, but once you wrap your head around it, it become second nature and very powerful.</p>
<p>Let me know what you think, or if you have any questions.
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2011/07/27/a-pattern-for-initializing-objective-c-objects-with-blocks/" data-counturl="http://blog.mikefullerton.com/2011/07/27/a-pattern-for-initializing-objective-c-objects-with-blocks/" data-text="a pattern for initializing objective-c objects with blocks" class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F07%2F27%2Fa-pattern-for-initializing-objective-c-objects-with-blocks%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2011/07/27/a-pattern-for-initializing-objective-c-objects-with-blocks/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F07%2F27%2Fa-pattern-for-initializing-objective-c-objects-with-blocks%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2011/07/27/a-pattern-for-initializing-objective-c-objects-with-blocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[[blog instance] reboot];</title>
		<link>http://blog.mikefullerton.com/2011/07/20/blog-instance-reboot/</link>
		<comments>http://blog.mikefullerton.com/2011/07/20/blog-instance-reboot/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 02:19:56 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mikefullerton.com/?p=1689</guid>
		<description><![CDATA[I view this blog reboot as an experiment. The basic premise is that I want to see if I can write some stuff here that will actually help people &#8211; specifically with iOS and Cocoa development. I&#8217;ve spent the last two years on an intensive crash course with this stuff and I&#8217;ve got about twenty [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I view this blog reboot as an experiment. The basic premise is that I want to see if I can write some stuff here that will actually help people &#8211; specifically with iOS and Cocoa development.</p>
<p>I&#8217;ve spent the last two years on an intensive crash course with this stuff and I&#8217;ve got about twenty years experience shipping software now, so maybe I just might have something to say.</p>
<p>I&#8217;ve read a lot of blog posts and discussions here and there on the web that have helped me, and now maybe I can help someone else and give back a bit a bit&#8230;</p>
<p>Not sure if the timing of Apple releasing Lion and me doing this have any great meaning. Probably not. But I&#8217;ll take what I can get.</p>
<p>So, anyway, I updated my wordpress install and installed a new theme, and off we go&#8230;
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2011/07/20/blog-instance-reboot/" data-counturl="http://blog.mikefullerton.com/2011/07/20/blog-instance-reboot/" data-text="[[blog instance] reboot];" class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F07%2F20%2Fblog-instance-reboot%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2011/07/20/blog-instance-reboot/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2011%2F07%2F20%2Fblog-instance-reboot%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2011/07/20/blog-instance-reboot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Teddy gets his first bath</title>
		<link>http://blog.mikefullerton.com/2008/02/21/teddy-gets-his-first-bath/</link>
		<comments>http://blog.mikefullerton.com/2008/02/21/teddy-gets-his-first-bath/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 06:24:47 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mikefullerton.com/blog/2008/02/21/TeddyGetsHisFirstBath.aspx</guid>
		<description><![CDATA[.flickr-photo { border: solid 2px #000000; } .flickr-yourcomment { } .flickr-frame { text-align: left; padding: 3px; } .flickr-caption { font-size: 0.8em; margin-top: 0px; } _DSC6213, originally uploaded by Mike and Bunny.]]></description>
			<content:encoded><![CDATA[<p></p><style type="text/css" xmlns="http://www.blogml.com/2006/09/BlogML">
.flickr-photo { border: solid 2px #000000; }
.flickr-yourcomment { }
.flickr-frame { text-align: left; padding: 3px; }
.flickr-caption { font-size: 0.8em; margin-top: 0px; }
</style>
<div class="flickr-frame" xmlns="http://www.blogml.com/2006/09/BlogML"><a href="http://www.flickr.com/photos/mikeandbunny/2281368894/" title="photo sharing"><img src="http://farm4.static.flickr.com/3065/2281368894_d8979bc8c2.jpg" class="flickr-photo" alt="" /></a><br /><span class="flickr-caption"><a href="http://www.flickr.com/photos/mikeandbunny/2281368894/">_DSC6213</a>, originally uploaded by <a href="http://www.flickr.com/people/mikeandbunny/">Mike and Bunny</a>.</span></div>
<p class="flickr-yourcomment" xmlns="http://www.blogml.com/2006/09/BlogML" />
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2008/02/21/teddy-gets-his-first-bath/" data-counturl="http://blog.mikefullerton.com/2008/02/21/teddy-gets-his-first-bath/" data-text="Teddy gets his first bath" class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2008%2F02%2F21%2Fteddy-gets-his-first-bath%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2008/02/21/teddy-gets-his-first-bath/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2008%2F02%2F21%2Fteddy-gets-his-first-bath%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2008/02/21/teddy-gets-his-first-bath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tiny Dog. Huge pants.</title>
		<link>http://blog.mikefullerton.com/2008/02/20/tiny-dog-huge-pants/</link>
		<comments>http://blog.mikefullerton.com/2008/02/20/tiny-dog-huge-pants/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 07:38:41 +0000</pubDate>
		<dc:creator>Mike Fullerton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mikefullerton.com/blog/2008/02/20/TinyDogHugePants.aspx</guid>
		<description><![CDATA[.flickr-photo { border: solid 2px #000000; } .flickr-yourcomment { } .flickr-frame { text-align: left; padding: 3px; } .flickr-caption { font-size: 0.8em; margin-top: 0px; } _DSC6117, originally uploaded by Mike and Bunny. This shot was under exposed, but I like it anyway.]]></description>
			<content:encoded><![CDATA[<p></p><style type="text/css" xmlns="http://www.blogml.com/2006/09/BlogML">
.flickr-photo { border: solid 2px #000000; }
.flickr-yourcomment { }
.flickr-frame { text-align: left; padding: 3px; }
.flickr-caption { font-size: 0.8em; margin-top: 0px; }
</style>
<div class="flickr-frame" xmlns="http://www.blogml.com/2006/09/BlogML"><a href="http://www.flickr.com/photos/mikeandbunny/2279215928/" title="photo sharing"><img src="http://farm3.static.flickr.com/2322/2279215928_df8594e64d.jpg" class="flickr-photo" alt="" /></a><br /><span class="flickr-caption"><a href="http://www.flickr.com/photos/mikeandbunny/2279215928/">_DSC6117</a>, originally uploaded by <a href="http://www.flickr.com/people/mikeandbunny/">Mike and Bunny</a>.</span></div>
<p class="flickr-yourcomment" xmlns="http://www.blogml.com/2006/09/BlogML">
	This shot was under exposed, but I like it anyway.
</p>
<div class="social4i" style="height:69px;">
<div class="social4in" style="height:69px;float: right;">
<div class="socialicons s4twitter" style="float:left;margin-right: 10px;"><a href="http://twitter.com/share" data-url="http://blog.mikefullerton.com/2008/02/20/tiny-dog-huge-pants/" data-counturl="http://blog.mikefullerton.com/2008/02/20/tiny-dog-huge-pants/" data-text="Tiny Dog. Huge pants." class="twitter-share-button" data-count="vertical" data-via=""></a></div>
<div class="socialicons s4fblike" style="float:left;margin-right: 10px;">
<div id="fb-root"></div>
<p><fb:like href="http%3A%2F%2Fblog.mikefullerton.com%2F2008%2F02%2F20%2Ftiny-dog-huge-pants%2F" send="false" layout="box_count" width="55" height="62" show_faces="false" font=""></fb:like></div>
<div class="socialicons s4plusone" style="float:left;margin-right: 10px;"><g:plusone size="tall" href="http://blog.mikefullerton.com/2008/02/20/tiny-dog-huge-pants/" count="true"></g:plusone></div>
<div class="socialicons s4fbshare" style="position: relative;height: 60px;width:61px;float:left;margin-right: 10px;">
<div class="s4ifbshare" style="position: absolute; bottom: 0pt;"><a name="fb_share" type="box_count" share_url="http%3A%2F%2Fblog.mikefullerton.com%2F2008%2F02%2F20%2Ftiny-dog-huge-pants%2F" href="http://www.facebook.com/sharer.php"></a></div>
</div>
</div>
<div style="clear:both"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.mikefullerton.com/2008/02/20/tiny-dog-huge-pants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

