<?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>Tewha &#187; Cocoa Touch</title>
	<atom:link href="http://tewha.net/tag/cocoa-touch/feed/" rel="self" type="application/rss+xml" />
	<link>http://tewha.net</link>
	<description>Writings and links on iPhone and iPad programming</description>
	<lastBuildDate>Wed, 18 Apr 2012 20:26:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Objective-C memory management</title>
		<link>http://tewha.net/2011/08/objective-c-memory-management/</link>
		<comments>http://tewha.net/2011/08/objective-c-memory-management/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 21:34:37 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[memory management]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=1232</guid>
		<description><![CDATA[With Automatic Reference Counting (ARC) coming out soon, you could argue this post is coming almost too late. But there&#8217;s a lot of confusion over this, and I don&#8217;t think ARC will help much if you don&#8217;t understand the why &#8230; <a href="http://tewha.net/2011/08/objective-c-memory-management/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>With Automatic Reference Counting (ARC) coming out soon, you could argue this post is coming almost too late. But there&#8217;s a lot of confusion over this, and I don&#8217;t think ARC will help much if you don&#8217;t understand the <em>why</em> of memory management.</p>

<p>After a couple years, I&#8217;ve come to adopt some very simple rules for memory management.</p>

<h2>Concepts</h2>

<p>The first step is to pick up a few concepts that will help you as you code.</p>

<ul>
<li><strong>Be lazy in memory management.</strong> Rely on the compiler to do everything it possibly can. The compiler can synthesize property setters that handle memory management according to the rules you set. Rely on this.</li>
<li><strong>Ownership.</strong> Think in terms of ownership, rather than reference counting. Thinking in terms of ownership makes problems and solutions obvious. Thinking in terms of ownership will help you keep in mind the <em>why</em> of what you&#8217;re doing, rather than the <em>what</em>. After you&#8217;ve got a good grasp of <em>why</em>, the <em>what</em> becomes obvious.</li>
<li><strong>Protect your objects.</strong> Own any object that you want to keep around as long as <code>self</code> is around.</li>
<li><strong>Avoid circular references.</strong> Never own an object that could own <code>self</code>. This means never owning <code>self</code>&#8216;s delegate or data source.</li>
</ul>

<h2>Practical guidelines</h2>

<p>But how does this translate to code? There&#8217;s a few specific and concrete things you can do to make this easier on yourself:</p>

<ul>
<li><strong>Use properties to centralize memory management rules.</strong> Use <code>@property</code> to establish the rules for memory management of an instance variable. (And <code>@synthesize</code> your properties to underscored instance variables to prevent naming conflicts.)</li>
<li><strong>Pick the right memory management rule.</strong> Use <code>retain</code> properties as your default. Data sources, delegates or other objects that might own the object you&#8217;re working in should be <code>assign</code> properties instead of <code>retain</code>.</li>
<li><strong>Rely on the centralized memory management rules.</strong> Use property set notation (<code>self.foo = nil;</code>) or the property setter (<code>[self setFoo: nil];</code>) everywhere you change the property&#8217;s value except in the property&#8217;s setter (if you need one) In this way, you rely on the <code>retain</code> or <code>assign</code> in your <code>@property</code> to specify the memory management. If you need to use <code>retain</code>, <code>release</code> or <code>autorelease</code> outside of a setter you&#8217;re doing too much. (And, also, you&#8217;ll have more work to do to be compatible with ARC.)</li>
<li><strong>Avoid being called once deallocated.</strong> In <code>dealloc</code>, <code>nil</code> any delegates you&#8217;ve set to <code>self</code>. (This eliminates the possibility that the object will survive longer than <code>self</code> and try to send messages to <code>self</code>.)</li>
<li><strong>Protect your private bits, too.</strong> Don&#8217;t use raw instance variables in objects requiring memory management. Use anonymous properties.</li>
<li><strong>Containers own their contents.</strong> You not only don&#8217;t need to but must not try to manage memory in a system container. An <code>NSArray</code> will send a <code>retain</code> to objects that are added to it, and a <code>release</code> to objects as they are removed. If you try to manually <code>retain</code> and <code>release</code> objects, you&#8217;ll miss a case.</li>
<li><strong>Verify.</strong> Analyze your code frequently. And profile your code early and often for leaks.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2011/08/objective-c-memory-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Annotating source for clang</title>
		<link>http://tewha.net/2011/02/annotating-source-for-clang/</link>
		<comments>http://tewha.net/2011/02/annotating-source-for-clang/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 19:58:29 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[better source code]]></category>
		<category><![CDATA[clang]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Cocoa Touch]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=1155</guid>
		<description><![CDATA[You can annotate your sources for better clang results. Best use is probably to specify that certain parameters to your functions can&#8217;t be nil/null. (via Peter Hosey on Twitter.)]]></description>
			<content:encoded><![CDATA[<p>You can annotate your sources for <a href="http://clang-analyzer.llvm.org/annotations.html">better clang results</a>. Best use is probably to specify that certain parameters to your functions <a href="http://twitter.com/boredzo/status/36873262134726656">can&#8217;t be nil/null</a>. (via <a href="https:/twitter.com/boredzo">Peter Hosey</a> on Twitter.)</p>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2011/02/annotating-source-for-clang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C99 structure initialization</title>
		<link>http://tewha.net/2010/12/c99-structure-initialization/</link>
		<comments>http://tewha.net/2010/12/c99-structure-initialization/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 04:55:43 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[C99]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iOS Development]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=1147</guid>
		<description><![CDATA[Dave Dribin (now of Apple): Fun with C99 Syntax. From May 2010, but I missed it then: C99 offers a better syntax than NSMakeRect.]]></description>
			<content:encoded><![CDATA[<p>Dave Dribin (now of Apple): <a href="http://www.dribin.org/dave/blog/archives/2010/05/15/c99_syntax/"> Fun with C99 Syntax</a>. From May 2010, but I missed it then: C99 offers a better syntax than NSMakeRect.</p>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2010/12/c99-structure-initialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Objective-C 2.2 Features</title>
		<link>http://tewha.net/2010/06/objective-c-2-2-features/</link>
		<comments>http://tewha.net/2010/06/objective-c-2-2-features/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 20:28:11 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[runtime]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=1119</guid>
		<description><![CDATA[Martin Pilkington (Code Collector Pro) on Objective-C 2.2 features. He covers the code reduction features of the new runtime. These are coming to &#8220;modern&#8221; Apple runtimes, meaning 64-bit Mac and iPhone.]]></description>
			<content:encoded><![CDATA[<p>Martin Pilkington (Code Collector Pro) on <a href="http://www.mcubedsw.com/blog/index.php/site/comments/new_objective-c_features/">Objective-C 2.2 features</a>. He covers the code reduction features of the new runtime. These are coming to &#8220;modern&#8221; Apple runtimes, meaning 64-bit Mac and iPhone.</p>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2010/06/objective-c-2-2-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Control and configuration of applications through Info.plist</title>
		<link>http://tewha.net/2009/08/control-and-configuration-of-applications-through-info-plist/</link>
		<comments>http://tewha.net/2009/08/control-and-configuration-of-applications-through-info-plist/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 19:11:16 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Info.post]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=1019</guid>
		<description><![CDATA[Matt Gallagher (Cocoa with Love): Control and configuration of applications through Info.plist. I hadn&#8217;t heard of UIRequiresPersistentWiFi before, so this will be helpful to me.]]></description>
			<content:encoded><![CDATA[<p>Matt Gallagher (Cocoa with Love): <a href="http://cocoawithlove.com/2009/08/control-and-configuration-of.html">Control and configuration of applications through Info.plist</a>. I hadn&#8217;t heard of <code>UIRequiresPersistentWiFi</code> before, so this will be helpful to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2009/08/control-and-configuration-of-applications-through-info-plist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make your iPhone application start faster</title>
		<link>http://tewha.net/2009/07/how-to-make-your-iphone-application-start-faster/</link>
		<comments>http://tewha.net/2009/07/how-to-make-your-iphone-application-start-faster/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 16:30:46 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iOS Development]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=963</guid>
		<description><![CDATA[James Thomson (PCalc): How to make your iPhone application start faster]]></description>
			<content:encoded><![CDATA[<p>James Thomson (PCalc): <a href="http://www.dragthing.com/blog/?p=246">How to make your iPhone application start faster</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2009/07/how-to-make-your-iphone-application-start-faster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three20</title>
		<link>http://tewha.net/2009/07/three20/</link>
		<comments>http://tewha.net/2009/07/three20/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 06:12:42 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[iOS Development]]></category>
		<category><![CDATA[User interface]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=953</guid>
		<description><![CDATA[I downloaded the latest version of Three20 today by Joe Hewitt. I read through some of the code and ran through the included &#8220;catalog&#8221; demo. If you&#8217;ve used the Facebook application, you&#8217;ve seen early versions of a lot of these &#8230; <a href="http://tewha.net/2009/07/three20/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I downloaded the latest version of <a href="http://github.com/joehewitt/three20/tree/master">Three20</a> today by <a href="http://joehewitt.com/">Joe Hewitt</a>. I read through some of the code and ran through the included &#8220;catalog&#8221; demo. If you&#8217;ve used the Facebook application, you&#8217;ve seen early versions of a lot of these controls.</p>

<p>I haven&#8217;t written any code against it yet and I&#8217;m not up to reviewing it, but I will say this: The controls seem to fully work. They&#8217;re pretty, and the code is clean.</p>

<p>Possibly the piece that will save me the most time going forward is the photo browser. I&#8217;m not sure yet when I&#8217;ll need this, but doing it myself would be a lot of effort at my current knowledge of Cocoa Touch:</p>

<p><img class="aligncenter size-full wp-image-955" title="Three20photos" src="http://tewha.net/wp-content/uploads/2009/07/Three20photos.png" alt="Three20photos" width="414" height="770">Less visually impressive, maybe, are the buttons:</p>

<p><img class="aligncenter size-full wp-image-954" title="Three20buttons" src="http://tewha.net/wp-content/uploads/2009/07/Three20buttons.png" alt="Three20buttons" width="414" height="770">But it&#8217;s worth pointing out that in addition to having more varied styling, these are built on <code>UIView</code> not <code>UIBarItem</code>. These are going to be very useful. I&#8217;m not exaggerating when I say they&#8217;ll make it possible to write better applications.</p>

<p>Three20 also has some tab controls. The top one in particular has a great sideways scroll to it, and I think look and behavior adds up to great UI device, which I can use immediately:</p>

<p><img class="aligncenter size-full wp-image-956" title="Three20tabs" src="http://tewha.net/wp-content/uploads/2009/07/Three20tabs.png" alt="Three20tabs" width="414" height="770">Next, some styled views:</p>

<p><img class="aligncenter size-full wp-image-957" title="Three20views" src="http://tewha.net/wp-content/uploads/2009/07/Three20views.png" alt="Three20views" width="414" height="770">Not pictured:</p>

<ul>
<li>Three20 includes &#8220;disk&#8221; based caching for network images.</li>

    <li>Three20 provides easy tools for building a text representation of the application state. This will make restoring state between runs much easier.</li>

</ul>

<p>Some of what&#8217;s in the library has been rendered unnecessary by iPhone OS 3.0, but there is enough added to make it very compelling. I plan on putting it to use soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2009/07/three20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Die you damn, dirty tab bar</title>
		<link>http://tewha.net/2009/07/die-you-damn-dirty-tab-bar/</link>
		<comments>http://tewha.net/2009/07/die-you-damn-dirty-tab-bar/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 03:14:20 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[UINavigationController]]></category>
		<category><![CDATA[UITabBar]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=877</guid>
		<description><![CDATA[Justin Williams: Die you damn, dirty tab bar.]]></description>
			<content:encoded><![CDATA[<p>Justin Williams: <a href="http://carpeaqua.com/2009/07/08/die-you-damn-dirty-tab-bar/">Die you damn, dirty tab bar</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2009/07/die-you-damn-dirty-tab-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The impact of the iPhone 3GS RAM increase</title>
		<link>http://tewha.net/2009/07/the-impact-of-the-iphone-3gs-ram-increase/</link>
		<comments>http://tewha.net/2009/07/the-impact-of-the-iphone-3gs-ram-increase/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 21:52:30 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=875</guid>
		<description><![CDATA[John Casasanta (Tap tap tap) on the impact of the iPhone 3GS RAM increase. Pretty memory usage graphs.]]></description>
			<content:encoded><![CDATA[<p>John Casasanta (Tap tap tap) on <a href="http://www.taptaptap.com/blog/the-impact-of-the-iphone-3gs-ram-increase/">the impact of the iPhone 3GS RAM increase</a>. Pretty memory usage graphs.</p>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2009/07/the-impact-of-the-iphone-3gs-ram-increase/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSURL synchronous requests</title>
		<link>http://tewha.net/2009/07/nsurl-synchronous-requests/</link>
		<comments>http://tewha.net/2009/07/nsurl-synchronous-requests/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 18:06:15 +0000</pubDate>
		<dc:creator>Steven Fisher</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[NSURL]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://tewha.net/?p=870</guid>
		<description><![CDATA[Can&#8217;t verify this yet, but something I want to investigate later: Chris Parker (who &#8220;works for a fruit company in Cupertino&#8221;) via Twitter: Hey iPhone devs: sending synchronous requests via NSURL on the main thread is a good way to &#8230; <a href="http://tewha.net/2009/07/nsurl-synchronous-requests/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Can&#8217;t verify this yet, but something I want to investigate later:</p>

<p><a href="http://twitter.com/ctp/status/2536073877">Chris Parker</a> (who &#8220;works for a fruit company in Cupertino&#8221;) via Twitter:</p>

<blockquote>Hey iPhone devs: sending synchronous requests via NSURL on the main thread is a good way to have SpringBoard kill you. Don&#8217;t do that.</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://tewha.net/2009/07/nsurl-synchronous-requests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: tewha.net @ 2012-05-22 11:23:51 -->
