<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" 
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
	<channel>
<title>Cocoa Dev</title><link>http://homepage.mac.com/berbie/TrailRunner/index.html</link><description>Developer Blog</description><dc:language>(null)</dc:language><dc:creator>w.berberich@salient.de</dc:creator><dc:rights>Copyright 2007 Berbie</dc:rights><dc:date>2007-11-17T18:25:53+01:00</dc:date><admin:generatorAgent rdf:resource="http://www.realmacsoftware.com/" />
<admin:errorReportsTo rdf:resource="mailto:w.berberich@salient.de" /><sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
<lastBuildDate>Sat, 28 Jun 2008 21:48:21 +0200</lastBuildDate><item><title>Macro Goodness</title><dc:creator>w.berberich@salient.de</dc:creator><dc:subject>Cocoa Dev</dc:subject><dc:date>2007-11-17T18:25:53+01:00</dc:date><link>http://homepage.mac.com/berbie/TrailRunner/page10/files/1f59702a42d842076b0f2a2981dfdc65-3.html#unique-entry-id-3</link><guid isPermaLink="true">http://homepage.mac.com/berbie/TrailRunner/page10/files/1f59702a42d842076b0f2a2981dfdc65-3.html#unique-entry-id-3</guid><content:encoded><![CDATA[If you read books on programming they all tell you to write documented code. But even better is to write compact code. Code that is so compact, it can even document itself. Objective-C is already pretty self documenting but some common conventions require you to write the same kind of code ever and ever again, just to follow these conventions. Macros have been ever very helpful in these cases. Following some examples. You can imagine how many macros like this I use in my code. <br /><br />Objective C 2.0 will make the whole retain release cycle go away but I am still sticked to Tiger. <br /><br /><span style="font:10px Monaco; "><pre><code><br /><span style="color: #000;">+&nbsp;(</span><span style="color: #00C;">void</span><span style="color: #000;">)</span><span style="color: #000;">setSomeReference</span><span style="color: #000;">:(</span><span style="color: #000;">NSObject</span><span style="color: #000;">&nbsp;*)</span><span style="color: #000;">object</span><span style="color: #000;"><br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">BEReferenceWithRetain</span><span style="color: #000;">(</span><span style="color: #000;">_myStrongReference</span><span style="color: #000;">,&nbsp;</span><span style="color: #000;">object</span><span style="color: #000;">);<br />}<br /></span></code></pre><br /></span><br />Uses this macro. I have others for <span style="font:10px Monaco; color:#643820;">BEReferenceWithCopy, BERelease </span>and more. <br /><br /><span style="font:10px Monaco; color:#643820;"><pre><code><br /><span style="color: #00C;">#define</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">BEReferenceWithRetain</span><span style="color: #000;">(</span><span style="color: #000;">a</span><span style="color: #000;">,&nbsp;</span><span style="color: #000;">b</span><span style="color: #000;">)&nbsp;\<br />{&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">id</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">bb</span><span style="color: #000;">&nbsp;=&nbsp;</span><span style="color: #000;">b</span><span style="color: #000;">;&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">if</span><span style="color: #000;">&nbsp;(</span><span style="color: #000;">a</span><span style="color: #000;">&nbsp;!=&nbsp;</span><span style="color: #000;">bb</span><span style="color: #000;">)&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">if</span><span style="color: #000;">&nbsp;(</span><span style="color: #000;">bb</span><span style="color: #000;">&nbsp;!=&nbsp;</span><span style="color: #00C;">nil</span><span style="color: #000;">)&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #000;">bb</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">retain</span><span style="color: #000;">];&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #000;">a</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">release</span><span style="color: #000;">];&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">a</span><span style="color: #000;">&nbsp;=&nbsp;</span><span style="color: #000;">bb</span><span style="color: #000;">;&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;\<br />}<br /></span></code></pre><br /><br /></span>Another common task is adding elements to a result set or array. If nothing should be added the method might return nil, but otherwise the resultArray. So this code is a very common task:<br /><span style="font:10px Monaco; color:#643820;"><br /><pre><code><br /><span style="color: #000;">NSMutableArray</span><span style="color: #000;">&nbsp;*</span><span style="color: #000;">resultArray</span><span style="color: #000;">&nbsp;=&nbsp;</span><span style="color: #00C;">nil</span><span style="color: #000;">;<br /><br /></span><span style="color: #00C;">while</span><span style="color: #000;">&nbsp;(</span><span style="color: #000;">someLoop</span><span style="color: #000;">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">if</span><span style="color: #000;">&nbsp;(</span><span style="color: #000;">shouldNotAdd</span><span style="color: #000;">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">continue</span><span style="color: #000;">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">BEAddObjectToMutableArray</span><span style="color: #000;">(</span><span style="color: #000;">resultArray</span><span style="color: #000;">,&nbsp;</span><span style="color: #000;">newItem</span><span style="color: #000;">);<br />}<br /></span></code></pre><br /><br /></span>It uses this macro<br /><span style="font:10px Monaco; color:#643820;"><br /><pre><code><br /><span style="color: #00C;">#define</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">BEAddObjectToMutableArray</span><span style="color: #000;">(</span><span style="color: #000;">array</span><span style="color: #000;">,&nbsp;</span><span style="color: #000;">item</span><span style="color: #000;">)&nbsp;\<br />{&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">if</span><span style="color: #000;">&nbsp;(</span><span style="color: #000;">item</span><span style="color: #000;">)&nbsp;{&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">if</span><span style="color: #000;">&nbsp;(</span><span style="color: #000;">array</span><span style="color: #000;">&nbsp;==&nbsp;</span><span style="color: #00C;">NULL</span><span style="color: #000;">)&nbsp;{\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">array</span><span style="color: #000;">&nbsp;=&nbsp;[</span><span style="color: #000;">NSMutableArray</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">arrayWithObject</span><span style="color: #000;">:</span><span style="color: #000;">item</span><span style="color: #000;">];&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #00C;">else</span><span style="color: #000;">&nbsp;{\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span><span style="color: #000;">array</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">addObject</span><span style="color: #000;">:</span><span style="color: #000;">item</span><span style="color: #000;">];&nbsp;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\<br />&nbsp;&nbsp;&nbsp;&nbsp;}\<br />}<br /></span></code></pre></span>]]></content:encoded></item><item><title>&#x5b;NSURLConnection sendSynchronousRequest:returningResponse:error:&#x5d;</title><dc:creator>w.berberich@salient.de</dc:creator><dc:subject>Cocoa Dev</dc:subject><dc:date>2007-11-17T18:23:28+01:00</dc:date><link>http://homepage.mac.com/berbie/TrailRunner/page10/files/ade5ca227831013abe76f9f4089a4dfc-1.html#unique-entry-id-1</link><guid isPermaLink="true">http://homepage.mac.com/berbie/TrailRunner/page10/files/ade5ca227831013abe76f9f4089a4dfc-1.html#unique-entry-id-1</guid><content:encoded><![CDATA[I had a lot of trouble with this beast in Tiger and it came up in Leopard again. As I did not find any solutions elsewhere, here's how I fixed it for me.<br /><br /><strong>Problem</strong>: NSURLConnection sendSynchronousRequest:returningResponse:error starts a download and blocks the calling thread until all bytes are received from the stream. In most cases this just works. But for some reason, if you call this on the main thread, it sometimes does not unlock the thread resulting in an application hang.<br /><strong>Lesson Learned</strong>: Fully synchronous url requests are impossible. Always load networks resources from a background thread.<br /><br /><strong>Next problem</strong>: Code Data loads an XML data store using this method. So it's no wonder that sometimes, when the arraycontroller gets filled, your application just hangs. Or, under Tiger, crashes because the NSData the store loads the XML into gets deallocated before the store is even finished loading.<br /><span style="font:10px Monaco; "><br /></span><strong>Solution: </strong>To fix this, I wrote a category for <span style="font:10px Monaco; ">NSXMLDocument </span>that loads file resources using standard file methods. Otherwise it does what I expect it to do in the default implementation.<br /><span style="font:10px Monaco; "><br /></span><span style="font:10px Monaco; color:#AA0D91;"><pre><code><br /><span style="color: #000;">-&nbsp;(</span><span style="color: #00C;">id</span><span style="color: #000;">)</span><span style="color: #000;">initWithContentsOfURL</span><span style="color: #000;">:(</span><span style="color: #000;">NSURL</span><span style="color: #000;">&nbsp;*)</span><span style="color: #000;">url</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">options</span><span style="color: #000;">:(</span><span style="color: #00C;">unsigned</span><span style="color: #000;">&nbsp;</span><span style="color: #00C;">int</span><span style="color: #000;">)</span><span style="color: #000;">mask</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">error</span><span style="color: #000;">:(</span><span style="color: #000;">NSError</span><span style="color: #000;">&nbsp;**)</span><span style="color: #000;">error</span><span style="color: #000;"><br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">id</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">result</span><span style="color: #000;">&nbsp;=&nbsp;</span><span style="color: #00C;">nil</span><span style="color: #000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">NSData</span><span style="color: #000;">&nbsp;*</span><span style="color: #000;">data</span><span style="color: #000;">&nbsp;=&nbsp;</span><span style="color: #00C;">nil</span><span style="color: #000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">if</span><span style="color: #000;">&nbsp;([</span><span style="color: #000;">url</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">isFileURL</span><span style="color: #000;">])<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">data</span><span style="color: #000;">&nbsp;=&nbsp;[[</span><span style="color: #000;">NSData</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">alloc</span><span style="color: #000;">]&nbsp;</span><span style="color: #000;">initWithContentsOfFile</span><span style="color: #000;">:[</span><span style="color: #000;">url</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">path</span><span style="color: #000;">]];<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">else</span><span style="color: #000;"><br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">NSHTTPURLResponse</span><span style="color: #000;">&nbsp;*</span><span style="color: #000;">response</span><span style="color: #000;">&nbsp;=&nbsp;</span><span style="color: #00C;">NULL</span><span style="color: #000;">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">NSMutableURLRequest</span><span style="color: #000;">&nbsp;*</span><span style="color: #000;">request</span><span style="color: #000;">&nbsp;=&nbsp;[</span><span style="color: #000;">NSMutableURLRequest</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">requestWithURL</span><span style="color: #000;">:</span><span style="color: #000;">url</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">cachePolicy</span><span style="color: #000;">:</span><span style="color: #000;">NSURLRequestReloadIgnoringCacheData</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">timeoutInterval</span><span style="color: #000;">:</span><span style="color: #000;">10</span><span style="color: #000;">];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">data</span><span style="color: #000;">&nbsp;=&nbsp;[</span><span style="color: #000;">NSURLConnection</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">sendSynchronousRequest</span><span style="color: #000;">:</span><span style="color: #000;">request</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">returningResponse</span><span style="color: #000;">:&amp;</span><span style="color: #000;">response</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">error</span><span style="color: #000;">:</span><span style="color: #000;">error</span><span style="color: #000;">];<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000;">result</span><span style="color: #000;">&nbsp;=&nbsp;[</span><span style="color: #00C;">self</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">initWithData</span><span style="color: #000;">:</span><span style="color: #000;">data</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">options</span><span style="color: #000;">:</span><span style="color: #000;">mask</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">error</span><span style="color: #000;">:</span><span style="color: #000;">error</span><span style="color: #000;">];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #00C;">return</span><span style="color: #000;">&nbsp;</span><span style="color: #000;">result</span><span style="color: #000;">;<br />}<br /></span></code></pre></span>]]></content:encoded></item><item><title>Removing Leopard Marketing Features</title><dc:creator>w.berberich@salient.de</dc:creator><dc:subject>Cocoa Dev</dc:subject><dc:date>2007-11-17T17:34:01+01:00</dc:date><link>http://homepage.mac.com/berbie/TrailRunner/page10/files/6b83d96a8e3b2dca21bd7285caf4b84e-0.html#unique-entry-id-0</link><guid isPermaLink="true">http://homepage.mac.com/berbie/TrailRunner/page10/files/6b83d96a8e3b2dca21bd7285caf4b84e-0.html#unique-entry-id-0</guid><content:encoded><![CDATA[Not all of us like the new Leopard look although it's a great product. Here are some ways to make Leopard look more familiar to previous versions of Mac OS X. All tips require you to use the shell.<br /><strong><br /></strong><h3>Remove the translucent Menu Bar effect</h3><strong><br /></strong><img class="imageStyle" alt="Pasted Graphic" src="http://homepage.mac.com/berbie/TrailRunner/page10/files/page10_blog_entry0_1.jpg" width="305" height="72"/><strong><br /></strong><code>sudo defaults write /System/Library/LaunchDaemons/com.apple.WindowServer 'EnvironmentVariables' -dict 'CI_NO_BACKGROUND_IMAGE' 0.62</code><br /><strong><br /></strong><h3>Switch the dock to 2D mode</h3><strong><br /></strong><img class="imageStyle" alt="Pasted Graphic 1" src="http://homepage.mac.com/berbie/TrailRunner/page10/files/page10_blog_entry0_2.jpg" width="432" height="105"/><strong><br /></strong><code>defaults write com.apple.dock no-glass -boolean YES</code><br /><br /><h3>Remove the default space desktop image</h3><strong><br /></strong>Even though you might have set another desktop background, the Login window still shows the space theme. To login look more neutral move the Image away.<strong><br /></strong><code>sudo mv /System/Library/CoreServices/DefaultDesktop.jpg /System/Library/CoreServices/xDefaultDesktop.jpg </code><br /><strong><br /></strong>]]></content:encoded></item></channel>
</rss>