<?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>iOS 5 Programming: Pushing the limits</title>
	<atom:link href="http://iosptl.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://iosptl.com</link>
	<description>Developing Extraordinary Mobile Apps for Apple iPhone, iPad, and iPod Touch</description>
	<lastBuildDate>Wed, 09 May 2012 15:37: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>Weak timers</title>
		<link>http://iosptl.com/posts/weak-timers/</link>
		<comments>http://iosptl.com/posts/weak-timers/#comments</comments>
		<pubDate>Wed, 09 May 2012 15:37:27 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Book Updates]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=103</guid>
		<description><![CDATA[Chapter 6, page 123 has a potential memory leak in it. In this particular program, it&#8217;s not possible for this to really leak, but in general it&#8217;s worth understanding the correct way to approach it. In the example code, the view retains an infinitely-repeating NSTimer, for which the view is the target. This is a [...]]]></description>
			<content:encoded><![CDATA[<p>Chapter 6, page 123 has a potential memory leak in it. In this particular program, it&#8217;s not possible for this to really leak, but in general it&#8217;s worth understanding the correct way to approach it.</p>
<p>In the example code, the view retains an infinitely-repeating <code>NSTimer</code>, for which the view is the target. This is a retain loop, since <code>NSTimer</code> retains its target. There are various ways to fix this, but my favorite is to use a GCD timer with a weak reference to <code>self</code>:</p>
<p><code>
<pre>
__weak id weakSelf = self;
double delayInSeconds = 0.25;
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,
                                dispatch_get_main_queue());
dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0),
                          (unsigned)(delayInSeconds * NSEC_PER_SEC), 0);
dispatch_source_set_event_handler(_timer, ^{
  [weakSelf updateValues];
});
dispatch_resume(_timer);
</pre>
<p></code></p>
<p>It&#8217;s a little verbose, and you often may want to wrap it up in a helper function. But it&#8217;s nicely self-contained. The <a href="https://github.com/rnapier/ios5ptl/commit/09bdbad1669cba5550f0d08d03f774de92e43cd2">sample code</a> has been updated.</p>
<p>Thanks to Johan Kool (@johankool) for pointing out the original retain loop.</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/weak-timers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Going Offline Errata</title>
		<link>http://iosptl.com/posts/going-offline-errata/</link>
		<comments>http://iosptl.com/posts/going-offline-errata/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 01:45:45 +0000</pubDate>
		<dc:creator>iosptl</dc:creator>
				<category><![CDATA[Book Updates]]></category>
		<category><![CDATA[Chapter-17]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=96</guid>
		<description><![CDATA[In Chapter 17: Going Offline, page 324 The code the clears the cached data files has a minor issue. The code in the book is for(NSString *path in cachedItems) { [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; } The path variable in this code is just the file name and not the full path and as such, doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>In Chapter 17: Going Offline, page 324<br />
The code the clears the cached data files has a minor issue.</p>
<p>The code in the book is</p>
<blockquote><p>for(NSString *path in cachedItems) {<br />
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];<br />
}</p></blockquote>
<p>The path variable in this code is just the file name and not the full path and as such, doesn&#8217;t delete the cached data file. Thanks to Brian for pointing this out.</p>
<p>You should use the following code instead.</p>
<blockquote><p>for(NSString *path in cachedItems) {<br />
NSString *fullPath = [[self cacheDirectory] stringByAppendingPathComponent:path];<br />
[[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];<br />
}
</p></blockquote>
<p>&#8211;<br />
Mugunth</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/going-offline-errata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KVO Tradeoffs Errata</title>
		<link>http://iosptl.com/posts/kvo-tradeoffs-errata/</link>
		<comments>http://iosptl.com/posts/kvo-tradeoffs-errata/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 20:24:17 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Book Updates]]></category>
		<category><![CDATA[Chapter-15]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=93</guid>
		<description><![CDATA[In Chapter 15, I say: The first call to removeObsever:forKeyPath: removes both previous observers. The second call will crash. This may sound contrived, but consider the case where both you and your superclass are observing the same object’s property. There is no easy way to implement that without special knowledge about your superclass’s implementation. If [...]]]></description>
			<content:encoded><![CDATA[<p>In Chapter 15, I say:</p>
<blockquote><p>The first call to <code>removeObsever:forKeyPath:</code> removes both previous observers. The second call will crash. This may sound contrived, but consider the case where both you and your superclass are observing the same object’s property. There is no easy way to implement that without special knowledge about your superclass’s implementation. If your superclass is a UIKit class, you don’t have the source code to even find out what it’s observing. You just have to hope it doesn’t collide with you now or in the future.</p></blockquote>
<p>There are two problems here. First, there&#8217;s a typo on the first line. That should be <code>removeObserver:forKeyPath:</code> (thanks to Sean Whitsell for catching my missing &#8220;r&#8221;).</p>
<p>Second, and more critical, this paragraph isn&#8217;t true. If you and your superclass have both observed this object, you may remove the wrong observation (i.e. the wrong context may be removed), but it won&#8217;t crash. You can (and must) balance an equal number of calls to <code>addObserver:...</code> and <code>removeObserver:...</code>. I have no idea why I made this mistake. Thanks to Ben Shanfelder for pointing it out to me.</p>
<p>As a side note, iOS 5 finally adds <code>removeObserver:forKeyPath:context:</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/kvo-tradeoffs-errata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Singleton pattern</title>
		<link>http://iosptl.com/posts/the-singleton-pattern/</link>
		<comments>http://iosptl.com/posts/the-singleton-pattern/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 20:11:58 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Book Updates]]></category>
		<category><![CDATA[Chapter-4]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=90</guid>
		<description><![CDATA[In chapter 4, we recommend using +initialize to create singletons. This used to be a good pattern, but it&#8217;s become dated since the addition of Grand Central Dispatch. It&#8217;s time to update our pattern to modern tools. Our new recommendation is the GCD way (replace id with your classname): + (id)sharedManager { static id sharedManager; [...]]]></description>
			<content:encoded><![CDATA[<p>In chapter 4, we recommend using <code>+initialize</code> to create singletons. This used to be a good pattern, but it&#8217;s become dated since the addition of Grand Central Dispatch. It&#8217;s time to update our pattern to modern tools. Our new recommendation is the GCD way (replace <code>id</code> with your classname):</p>
<pre>+ (id)sharedManager
{
  static id sharedManager;
  static dispatch_once_t once;
  dispatch_once(&amp;once, ^{
    sharedManager = [[self alloc] init];
  });
  return sharedManager;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/the-singleton-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leading Underscores</title>
		<link>http://iosptl.com/posts/leading-underscores/</link>
		<comments>http://iosptl.com/posts/leading-underscores/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 20:05:33 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Book Updates]]></category>
		<category><![CDATA[Chapter-3]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=88</guid>
		<description><![CDATA[In Chapter 3, I said that Apple reserves leading underscores in ivar names. This isn&#8217;t true. Apple reserves leading underscores in method names, but not ivar names. While I believe avoiding a leading underscore was valuable in the past for the other reasons listed (particularly avoiding some KVC magic), with the move to auto-synthesized ivars [...]]]></description>
			<content:encoded><![CDATA[<p>In Chapter 3, I said that Apple reserves leading underscores in ivar names. This isn&#8217;t true. Apple reserves leading underscores in method names, but not ivar names.</p>
<p>While I believe avoiding a leading underscore was valuable in the past for the other reasons listed (particularly avoiding some KVC magic), with the move to auto-synthesized ivars this recommendation has become more trouble than its worth. In the future, our recommendation is to follow Xcode&#8217;s lead: readwrite ivars should have a leading underscore. readonly ivars should have a leading double-underscore. This double-underscore also fixes the KVC concern, so it wins in several ways.</p>
<p>Thanks to Mark Dalrymple (@borkware) for pointing out this issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/leading-underscores/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Even Faster Bezier</title>
		<link>http://iosptl.com/posts/even-faster-bezier/</link>
		<comments>http://iosptl.com/posts/even-faster-bezier/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 17:13:23 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Chapter-18]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=69</guid>
		<description><![CDATA[At Cocoaphony, I've been investigating how to speed up the calculation of Bézier curves, like the ones discussed in Chapter 18. In this next installment, learn how to dramatically improve performance by refactoring the math. This way of thinking is important to many optimization problems, and particularly tight inner loops like you find in computationally hard problems. <i>Read more at <a href="http://robnapier.net/blog/faster-bezier-722">Cocoaphony</a>.</i>]]></description>
			<content:encoded><![CDATA[<p>At Cocoaphony, I&#8217;ve been investigating how to speed up the calculation of Bézier curves, like the ones discussed in Chapter 18. In this next installment, learn how to dramatically improve performance by refactoring the math. This way of thinking is important to many optimization problems, and particularly tight inner loops like you find in computationally hard problems. <i>Read more at <a href="http://robnapier.net/blog/faster-bezier-722">Cocoaphony</a>.</i></p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/even-faster-bezier/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Fast Bezier (and trying the Accelerate.framework)</title>
		<link>http://iosptl.com/posts/fast-bezier-intro/</link>
		<comments>http://iosptl.com/posts/fast-bezier-intro/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 18:41:42 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Chapter-18]]></category>
		<category><![CDATA[Cocoaphony]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=74</guid>
		<description><![CDATA[So you want to hand-calculate Bézier curves. Good for you. It comes up more often then you’d think on iOS, even though UIBezierPath is supposed to do it all for you. The truth is, sometimes you need the numbers yourself. For instance if you want to calculate intersections, or you want to draw text along the curve (like in <a href="https://github.com/rnapier/ios5ptl/tree/master/ch18/CurvyText" target="_blank">CurvyText</a> from chapter 18).
]]></description>
			<content:encoded><![CDATA[<p>So you want to hand-calculate Bézier curves. Good for you. It comes up more often then you’d think on iOS, even though UIBezierPath is supposed to do it all for you. The truth is, sometimes you need the numbers yourself. For instance if you want to calculate intersections, or you want to draw text along the curve (like in <a href="https://github.com/rnapier/ios5ptl/tree/master/ch18/CurvyText" target="_blank">CurvyText</a> from chapter 18).<br />
<span id="more-74"></span><br />
CurvyText is pretty inefficient in how it calculates curves. The section was written to discuss Core Text, not fast calculations, so it keeps the math function simple. But Bézier curves can be calculated a lot faster. <em>Read more at <a href="http://robnapier.net/blog/fast-bezier-intro-701" target="_blank">Cocoaphony</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/fast-bezier-intro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chapter 9 __block correction</title>
		<link>http://iosptl.com/posts/chapter-9-block-correction/</link>
		<comments>http://iosptl.com/posts/chapter-9-block-correction/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 20:56:52 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Book Updates]]></category>
		<category><![CDATA[Chapter-9]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=67</guid>
		<description><![CDATA[Chapter 9 indicates that you should use a special __block copy of self to avoid retain loops. Under ARC, you need to add __weak (or at least __unsafe_unretained) copy of self.]]></description>
			<content:encoded><![CDATA[<p>In Chapter 9, &#8220;Controlling Multitasking,&#8221; there are several references to the following pattern:</p>
<p><code> __block typeof(self) myself = self;<br />
... ^{ // block that uses myself } ...<br />
</code></p>
<p>As noted on page 183, &#8220;if you reference an object inside of a block, the block automatically retains that object. If you reference <code>self</code>, a retain loop is created because <code>self</code> retains <code>queue</code>, which retains the block.&#8221;</p>
<p>This was correct for manual reference counting, but is not sufficient for ARC. With ARC, you need to add the <code>__weak</code> specifier as well, or you need to set the value to <code>nil</code> inside the block. As noted in the <a href="https://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html">Transitioning to ARC Release Notes</a>:</p>
<blockquote><p>In manual reference counting mode, <code>__block id x;</code> has the effect of not retaining <code>x</code>. In ARC mode, <code>__block id x;</code> defaults to retaining x (just like all other values). To get the manual reference counting mode behavior under ARC, you could use <code>__unsafe_unretained __block id x;</code>. As the name <code>__unsafe_unretained</code> implies, however, having a non-retained variable is dangerous (because it can dangle) and is therefore discouraged. Two better options are to either use <code>__weak</code> (if you don’t need to support iOS 4 or OS X v10.6), or set the <code>__block</code> value to <code>nil</code> to break the retain cycle.</p></blockquote>
<p>Thanks to Crispin Bennett for finding this error.</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/chapter-9-block-correction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MKNetworkKit</title>
		<link>http://iosptl.com/posts/mknetworkkit/</link>
		<comments>http://iosptl.com/posts/mknetworkkit/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 02:21:20 +0000</pubDate>
		<dc:creator>mugunthkumar</dc:creator>
				<category><![CDATA[Book Updates]]></category>
		<category><![CDATA[Chapter-10]]></category>
		<category><![CDATA[Chapter-17]]></category>
		<category><![CDATA[mknetworkkit]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=55</guid>
		<description><![CDATA[The original author of ASIHttpRequest, Ben Copsey has officially stopped supporting it. Most of the example from Chapters 10: REST for the Weary and Chapter  17: Going offline in the book iOS5:PTL would work the same when replaced with MKNetworkKit. I wrote MKNetworkKit so that it would be super easy for developers to migrate from [...]]]></description>
			<content:encoded><![CDATA[<p>The original author of ASIHttpRequest, Ben Copsey has <a href="http://allseeing-i.com/%5Brequest_release%5D">officially stopped supporting</a> it. Most of the example from Chapters 10: REST for the Weary and Chapter  17: Going offline in the book iOS5:PTL would work the same when replaced with <a href="http://mknetworkkit.com">MKNetworkKit</a>.</p>
<p>I wrote MKNetworkKit so that it would be super easy for developers to migrate from ASIHttpRequest. It&#8217;s feature rich, ARC only code based on NSURLConnection and supports pretty much everything that ASIHttpRequest supported.</p>
<p>MKNetworkKit also embraces the idea of writing cleaner view controller code that I discussed in the above mentioned chapters, 10 and 17.</p>
<p>You can read more about MKNetworkKit on the following blog posts.</p>
<p><a href="http://blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/">Introducing MKNetworkKit</a></p>
<p><a href="http://blog.mugunthkumar.com/coding/ios-tutorial-advanced-networking-with-mknetworkkit/">Advanced Networking with MKNetworkKit</a></p>
<p><a href="http://blog.mugunthkumar.com/coding/ios-tutorial-image-cache-and-loading-thumbnails-using-mknetworkkit/">Image Cache and Loading Thumbnails using MKNetworkKit</a></p>
<p>&#8211;</p>
<p>Mugunth</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/mknetworkkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drop-in offline caching for UIWebView (and NSURLProtocol)</title>
		<link>http://iosptl.com/posts/drop-in-offline-caching-for-uiwebview-and-nsurlprotocol/</link>
		<comments>http://iosptl.com/posts/drop-in-offline-caching-for-uiwebview-and-nsurlprotocol/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 15:21:16 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[uiwebview]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=38</guid>
		<description><![CDATA[Your programs need to deal gracefully with being offline. Mugunth Kumar has built an excellent toolkit that manages REST connections while offline called MKNetworkKit, and Chapter 17 of iOS:PTL is devoted to the ins-and-outs of this subject. But sometimes you just have a simple UIWebView, and you want to cache the last version of the page.]]></description>
			<content:encoded><![CDATA[<p>Your programs need to deal gracefully with being offline. Mugunth Kumar has built an excellent toolkit that manages REST connections while offline called <a href="https://github.com/MugunthKumar/MKNetworkKit">MKNetworkKit</a>, and Chapter 17 of <em>iOS:PTL</em> is devoted to the ins-and-outs of this subject. But sometimes you just have a simple <code>UIWebView</code>, and you want to cache the last version of the page.</p>
<p><span id="more-38"></span>You’d think that <code>NSURLCache</code> would handle this for you, but it’s much more complicated than that. <code>NSURLCache</code> doesn’t cache everything you’d think it would. Sometimes this is because of Apple’s decisions in order to save space. Just as often, however, it’s because the HTTP caching rules explicitly prevent caching a particular resource.</p>
<div><em> Read more at <a href="http://robnapier.net/blog/offline-uiwebview-nsurlprotocol-588">Cocoaphony</a>.</em></div>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/drop-in-offline-caching-for-uiwebview-and-nsurlprotocol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

