<?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 6 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, 10 Apr 2013 21:10:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>iOS 6 Chapter 8: UIRectFill() uses fill color, not stroke color</title>
		<link>http://iosptl.com/posts/ios-6-chapter-8-uirectfill-uses-fill-color-not-stroke-color/</link>
		<comments>http://iosptl.com/posts/ios-6-chapter-8-uirectfill-uses-fill-color-not-stroke-color/#comments</comments>
		<pubDate>Wed, 10 Apr 2013 21:10:27 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=227</guid>
		<description><![CDATA[On p142: [[UIColor redColor] setStroke]; CGContextSaveGState(UIGraphicsGetCurrentContext()); [[UIColor blackColor] setStroke]; CGContextRestoreGState(UIGraphicsGetCurrentContext()); UIRectFill(CGRectMake(10, 10, 100, 100)); // Red The calls to setStroke should be setFill. Thanks to Tan Yuguo for finding this.]]></description>
				<content:encoded><![CDATA[<p>On p142:</p>
<pre><code>[[UIColor redColor] setStroke];
CGContextSaveGState(UIGraphicsGetCurrentContext());
[[UIColor blackColor] setStroke];
CGContextRestoreGState(UIGraphicsGetCurrentContext());
UIRectFill(CGRectMake(10, 10, 100, 100)); // Red
</code></pre>
<p>The calls to <code>setStroke</code> should be <code>setFill</code>. Thanks to Tan Yuguo for finding this.</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/ios-6-chapter-8-uirectfill-uses-fill-color-not-stroke-color/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iOS 6 PTL: Chapter 2 Errata</title>
		<link>http://iosptl.com/posts/ios-6-ptl-chapter-2-errata/</link>
		<comments>http://iosptl.com/posts/ios-6-ptl-chapter-2-errata/#comments</comments>
		<pubDate>Sun, 16 Dec 2012 13:30:00 +0000</pubDate>
		<dc:creator>iosptl</dc:creator>
				<category><![CDATA[Book Updates]]></category>
		<category><![CDATA[errata]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=223</guid>
		<description><![CDATA[We made a typo in Chapter 2, section Collection Literals. The syntax for creating a new NSDictionary was written as &#160; NSDictionary *dict = @&#91;@&#34;key1&#34;:@&#34;value1&#34;, @&#34;key2&#34;:@&#34;value2&#34;, @&#34;key2&#34;:@&#34;value2&#34;&#93; The correct syntax is &#160; NSDictionary *dict = @&#123; @&#34;key1&#34;:@&#34;value1&#34;, @&#34;key2&#34;:@&#34;value2&#34;, @&#34;key3&#34;:@&#34;value3&#34; &#125; Curly braces are used for creating dictionaries and square brackets are used for creating arrays. [...]]]></description>
				<content:encoded><![CDATA[<p>We made a typo in Chapter 2, section Collection Literals.</p>
<p>The syntax for creating a new NSDictionary was written as</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>dict <span style="color: #002200;">=</span> @<span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;key1&quot;</span><span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;value1&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;key2&quot;</span><span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;value2&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;key2&quot;</span><span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;value2&quot;</span><span style="color: #002200;">&#93;</span></pre></td></tr></table></div>

<p>The correct syntax is</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>dict <span style="color: #002200;">=</span> @<span style="color: #002200;">&#123;</span>
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;key1&quot;</span><span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;value1&quot;</span>, 
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;key2&quot;</span><span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;value2&quot;</span>, 
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;key3&quot;</span><span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;value3&quot;</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p><strong>Curly braces are used for creating dictionaries and square brackets are used for creating arrays.</strong></p>
<p>In Object Subscripting section,<br />
when you access a element in an array using a subscript, you get a NSNumber</p>
<p>So the correct code that compiles without a warning is as below.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>array <span style="color: #002200;">=</span> @<span style="color: #002200;">&#91;</span>@1, @2, @3, @4, @5<span style="color: #002200;">&#93;</span>
<span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>elementAt3 <span style="color: #002200;">=</span> array<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">3</span><span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>Thanks to Luca Bernardi for pointing this out.</p>
<p>&#8211;<br />
Mugunth</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/ios-6-ptl-chapter-2-errata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;New&#8221; (well, not really new) PRF functions for PBKDF2</title>
		<link>http://iosptl.com/posts/new-prf-functions-for-pbkdf2/</link>
		<comments>http://iosptl.com/posts/new-prf-functions-for-pbkdf2/#comments</comments>
		<pubDate>Tue, 18 Sep 2012 14:58:46 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Book Updates]]></category>
		<category><![CDATA[Chapter-11]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=204</guid>
		<description><![CDATA[In Chapter 11, I indicated that the only PRF available for PBKDF2 was SHA-1. I believe this was true when it was written (during the early betas of iOS 5), but it was not true by the time iOS 5 was released. iOS offers both SHA-1 and SHA-2 PRFs for use in PBKDF2: enum { [...]]]></description>
				<content:encoded><![CDATA[<p>In Chapter 11, I indicated that the only PRF available for PBKDF2 was SHA-1. I believe this was true when it was written (during the early betas of iOS 5), but it was not true by the time iOS 5 was released. iOS offers both SHA-1 and SHA-2 PRFs for use in PBKDF2:</p>
<pre>enum {
    kCCPRFHmacAlgSHA1 = 1,
    kCCPRFHmacAlgSHA224 = 2,
    kCCPRFHmacAlgSHA256 = 3,
    kCCPRFHmacAlgSHA384 = 4,
    kCCPRFHmacAlgSHA512 = 5,
};</pre>
<p>SHA224-SAH512 are just specific sizes of SHA-2.</p>
<p>Note that while SHA-1 is <a href="http://www.schneier.com/blog/archives/2005/02/sha1_broken.html">&#8220;broken,&#8221;</a> the issues don&#8217;t impact the security of HMAC (let alone PBKDF2). SHA-1 still serves this function perfectly well. Even MD5 is still fine in this use. Intuitively, PBKDF2 doesn&#8217;t need a collision-resistant hash function at all because its goal is to waste time in a way that is difficult to short-cut with parallelization. (On the security proof side, HMAC does not require a strongly collision-resistent hash function in order to remain a PRF, and PBKDF2 only requires a PRF to maintain its security. See <a href="http://cseweb.ucsd.edu/~mihir/papers/hmac-new.html">Mihir Bellare&#8217;s</a> paper for details.)</p>
<p>As good security housekeeping, I would recommend that new implementations use SHA256 to help move the world from SHA-1 to SHA-2 a little faster. But I wouldn&#8217;t recommend expending much effort to retrofit old implementations at this time.</p>
<p>I haven&#8217;t yet done any timing analysis to determine a good number of PBKDF2 iterations for SHA256. SHA1 needs 10k iterations to give 80ms on a iPhone 4. ~100ms is a pretty good target IMO.</p>
<p>Thanks to Daniel McGloin for pointing this issue out to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/new-prf-functions-for-pbkdf2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title> iOS 6 Programming Pushing the Limits</title>
		<link>http://iosptl.com/posts/197/</link>
		<comments>http://iosptl.com/posts/197/#comments</comments>
		<pubDate>Mon, 10 Sep 2012 11:21:31 +0000</pubDate>
		<dc:creator>iosptl</dc:creator>
				<category><![CDATA[Book Updates]]></category>
		<category><![CDATA[announcements]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=197</guid>
		<description><![CDATA[A brief introduction of what&#8217;s up in the next edition, iOS 6 Programming Pushing the Limits. http://blog.mugunthkumar.com/products/ios-6-programming-pushing-the-limits/]]></description>
				<content:encoded><![CDATA[<p>A brief introduction of what&#8217;s up in the next edition, iOS 6 Programming Pushing the Limits.</p>
<p><a href="http://blog.mugunthkumar.com/products/ios-6-programming-pushing-the-limits/">http://blog.mugunthkumar.com/products/ios-6-programming-pushing-the-limits/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/197/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CGLayer no longer recommended</title>
		<link>http://iosptl.com/posts/cglayer-no-longer-recommended/</link>
		<comments>http://iosptl.com/posts/cglayer-no-longer-recommended/#comments</comments>
		<pubDate>Fri, 13 Jul 2012 14:03:49 +0000</pubDate>
		<dc:creator>robnapier</dc:creator>
				<category><![CDATA[Book Updates]]></category>

		<guid isPermaLink="false">http://iosptl.com/?p=114</guid>
		<description><![CDATA[CGLayer may be better on paper than in practice. My new recommendations are the very common CGBitmapContext or CALayer.]]></description>
				<content:encoded><![CDATA[<p>I spend a lot of time in the labs at WWDC asking questions and talking with the developers. I sat down the Core Graphics engineers this time and asked them about one of my favorite underused tools: CGLayer, which I discuss at the end of Chapter 6. CGLayer sounds like a great idea: a drawing context optimized specifically for drawing on the screen, with hardware optimization. What could go wrong?</p>
<p><span id="more-114"></span></p>
<p>I started to have doubts, though, that CGLayer was always a great win. What if your layers were too large to store in GPU textures? CGLayer is advertised for use as a &#8220;stamp&#8221; that you repeatedly draw. Moving data to and from the GPU is expensive. Maybe CGLayer doesn&#8217;t make sense unless you draw it a certain number of times. The docs give no guidance on this. So I asked the Core Graphics team &#8220;When should I be using CGLayer?&#8221;</p>
<p>&#8220;Never.&#8221;</p>
<p>&#8230; ??? Never? But for stamping right?</p>
<p>Never.</p>
<p>So we talked some more. It appears that CGLayer was one of those things that sounded great on paper, but just doesn&#8217;t always work in practice. Sometimes it&#8217;s faster. Sometimes its slower. There&#8217;s no easy rule for when it&#8217;s going to be faster. Over time it seems they&#8217;ve quietly abandoned it without actually deprecating it. I&#8217;ve asked that the docs be updated to match Apple&#8217;s current recommendation. The CGLayer Reference hasn&#8217;t been updated since 2006.</p>
<p>The recommendation I received was to use CGBitmapContext or CALayer for stamping. For the specific example given on pages 131-132, CATextLayer would probably be the best tool. Remember that you can easily clone a CALayer using initWithLayer:.</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/cglayer-no-longer-recommended/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<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>2</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>7</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[Have written something that you&#8217;d swear you&#8217;d never have written because it&#8217;s wrong and you know it&#8217;s wrong? But you did anyway? 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 [...]]]></description>
				<content:encoded><![CDATA[<p>Have written something that you&#8217;d swear you&#8217;d never have written because it&#8217;s wrong and you know it&#8217;s wrong? But you did anyway? 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 <a href="http://weblog.bignerdranch.com/463-a-motivation-for-ivar-decorations/">pointing out this issue</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://iosptl.com/posts/leading-underscores/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
