<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en"><title type="text">MKBlog</title><link rel="alternate" type="text/html" href="http://blog.mugunthkumar.com" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/MugunthKumar" /><subtitle type="html">iPhone, iPad, Windows Phone Development and Usability Guidelines</subtitle><updated>2012-02-24T02:47:50+00:00</updated><generator>http://wordpress.org/?v=3.3.1</generator><sy:updatePeriod xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">hourly</sy:updatePeriod><sy:updateFrequency xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">1</sy:updateFrequency><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/MugunthKumar" /><feedburner:info uri="mugunthkumar" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-sa/3.0/" /><feedburner:emailServiceId>MugunthKumar</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry><title type="text">iOS5 Programming: Pushing the limits book updates</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/pbRsGWJJwLc/" /><category term="Products" /><category term="book" /><category term="ios5" /><category term="ios5ptl" /><category term="iosptl" /><author><name>Mugunth Kumar</name></author><updated>2012-02-15T20:40:24-08:00</updated><id>http://blog.mugunthkumar.com/?p=1542</id><summary type="html">iOS5 Programming: Pushing the limits Rob and myself created a new website, iosptl.com where we will be posting minor updates to the book and other relevant information that might be of use to iOS developers. iOS is a cutting edge technology. Like everything on the cutting edge, it’s constantly growing and changing. A book captures [...]
Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/products/introducing-my-book-ios-5-programming-pushing-the-limits/' rel='bookmark' title='Introducing my book: iOS 5 Programming Pushing the Limits'&gt;Introducing my book: iOS 5 Programming Pushing the Limits&lt;/a&gt; &lt;small&gt;iOS 5 Programming Pushing the Limits Developing Extraordinary Mobile Apps...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://iosptl.com"&gt;iOS5 Programming: Pushing the limits&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Rob and myself created a new website, &lt;a href="http://iosptl.com"&gt;iosptl.com&lt;/a&gt; where we will be posting minor updates to the book and other relevant information that might be of use to iOS developers.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;iOS is a cutting edge technology. Like everything on the cutting edge, it’s constantly growing and changing. A book captures a moment in time, and &lt;em&gt;iOS:PTL&lt;/em&gt; captured the state of the art during the iOS 5 beta in 2011. Most things about iOS development don’t change from month to month, and we expect most of the book to be accurate long into the future. But some things do change, and this website will capture those updates so that the reader can have the most accurate information today.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Checkout the website and &lt;a href="http://iosptl.com/feed"&gt;subscribe to the feed&lt;/a&gt; or follow us on twitter for up to date information on the book.&lt;br /&gt;
&lt;a href="http://twitter.com/mugunthkumar"&gt;@mugunthkumar&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://twitter.com/cocoaphony"&gt;@cocoaphony&lt;/a&gt;&lt;br /&gt;
&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1542_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1542?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1542_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1542&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fproducts%2Fios5-programming-pushing-the-limits-book-updates%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/products/introducing-my-book-ios-5-programming-pushing-the-limits/' rel='bookmark' title='Introducing my book: iOS 5 Programming Pushing the Limits'&gt;Introducing my book: iOS 5 Programming Pushing the Limits&lt;/a&gt; &lt;small&gt;iOS 5 Programming Pushing the Limits Developing Extraordinary Mobile Apps...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/trms99hm1VJCgxHyQwRKHzoHrBQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/trms99hm1VJCgxHyQwRKHzoHrBQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/trms99hm1VJCgxHyQwRKHzoHrBQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/trms99hm1VJCgxHyQwRKHzoHrBQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/pbRsGWJJwLc" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/products/ios5-programming-pushing-the-limits-book-updates/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">2</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/products/ios5-programming-pushing-the-limits-book-updates/</feedburner:origLink></entry><entry><title type="text">Some thoughts on iOS and your privacy (Address Book)</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/q-P_VDlXVcM/" /><category term="Articles" /><category term="addressbook" /><category term="ios" /><category term="ios 5" /><category term="path" /><category term="privacy" /><category term="thoughts" /><author><name>Mugunth Kumar</name></author><updated>2012-02-07T23:00:17-08:00</updated><id>http://blog.mugunthkumar.com/?p=1504</id><summary type="html">The recent furore behind the fact that, Path, one of the most beautiful iOS app out there, uploads your entire address book to their servers when you create an account, is probably targeted at the wrong guys. Why do I say this? Read on. Who else is doing it? It&amp;#8217;s not just Path. Hipster is [...]
No related posts.</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;The recent furore behind the fact that, Path, one of the most beautiful iOS app out there, uploads your entire address book to their servers when you create an account, is probably targeted at the wrong guys. Why do I say this? Read on.&lt;/p&gt;
&lt;span id="Who_else_is_doing_it"&gt;&lt;h3&gt;Who else is doing it?&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;It&amp;#8217;s not just Path. Hipster is doing it. Whatsapp is doing it. Foursquare is doing it. &lt;a href="http://news.ycombinator.com/item?id=3565028"&gt;Instagram is doing it&lt;/a&gt;. Viber is doing it. &amp;#8220;Insert your new hot social networking app here&amp;#8221; is doing it. This tweet summarizes this.&lt;/p&gt;
&lt;blockquote class="twitter-tweet tw-align-center"&gt;&lt;p&gt;for those who just realized that Path uploads your entire address book:you&amp;#8217;re such a cute innocent person.Guess what they do with ur fb&lt;/p&gt;
&lt;p&gt;— Amudi Sebastian (@amudi) &lt;a href="https://twitter.com/amudi/status/167072379867107328" data-datetime="2012-02-08T02:28:54+00:00"&gt;February 8, 2012&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Some companies explicitly ask for users&amp;#8217; permission (Whatsapp and Viber)&lt;/p&gt;
&lt;p style="text-align: center;"&gt;
&lt;div class="wp-caption aligncenter" style="width: 154px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Whatsapp asking for user's permission to upload address book" src="http://blog.mugunthkumar.com/wp-content/uploads/Pastebot-2012-02-08-14.38.38-PM-4.png" alt="Whatsapp asking for user's permission to upload address book" width="144" height="216" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Whatsapp asking for user&amp;#39;s permission to upload address book&lt;/p&gt;&lt;/div&gt;
&lt;div class="wp-caption aligncenter" style="width: 154px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Viber asking for user's permission to upload address book" src="http://blog.mugunthkumar.com/wp-content/uploads/Pastebot-2012-02-08-14.38.38-PM-2.png" alt="Viber asking for user's permission to upload address book" width="144" height="216" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Viber asking for user&amp;#39;s permission to upload address book&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Some companies do it when the user explicitly ask them to do. For example, foursquare and Instagram both have an option called &amp;#8220;Find friends from Contacts&amp;#8221;.&lt;/p&gt;
&lt;p&gt;Instagram uploads when you ask it to find your friends from Contacts.&lt;/p&gt;
&lt;div class="wp-caption aligncenter" style="width: 154px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Instagram uploads your contacts when you tap on &amp;quot;From my contact list&amp;quot;" src="http://blog.mugunthkumar.com/wp-content/uploads/Pastebot-2012-02-08-14.45.57-PM-1.png" alt="Instagram uploads your contacts when you tap on &amp;quot;From my contact list&amp;quot;" width="144" height="216" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Instagram uploads your contacts when you tap on &amp;quot;From my contact list&amp;quot;&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Foursquare uploads &amp;#8220;proactively&amp;#8221; when you open the &amp;#8220;Invite Friends&amp;#8221; view. This is again as bad as Path.&lt;/p&gt;
&lt;div class="wp-caption aligncenter" style="width: 154px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Foursquare uploads in the background when you open this view" src="http://blog.mugunthkumar.com/wp-content/uploads/Pastebot-2012-02-08-14.45.57-PM-2.png" alt="Foursquare uploads in the background when you open this view" width="144" height="216" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Foursquare uploads in the background when you open this view&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;To a techie like you and me, we know that this option would upload the entire address book. To any other iOS user, it&amp;#8217;s not really clear. May be they should have added an additional prompt like Whatsapp. But then, that would _alert_ the user and he will probably opt out.&lt;/p&gt;
&lt;p&gt;Some companies bury it deep inside their privacy policy (that no one reads). While there are many bad examples, Viber really stands out as a good example. Their privacy policy explicitly states what all they do with the contacts they read from your device.&lt;/p&gt;
&lt;p&gt;But most company&amp;#8217;s privacy policy is written in legal lingo, mostly incomprehensible to the common man.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I&amp;#8217;m not arguing that two wrongs make a right&lt;/strong&gt;. The point I want to put forth is that, this is not a problem with the third party app maker. It&amp;#8217;s a platform issue. When a Android app steals your private information, why do you blame Google instead of the third party app developer? If Google allowed API access to your sensitive information using a opt-in dialog like iOS rather than a manifest file, would there be so many trojans on Android marketplace?&lt;/p&gt;
&lt;p&gt;The whole problem in this recent furore roots down to the security layer of iOS. iOS allows any programmer to access all of your address book with just two lines of code.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;ABAddressBookRef addressBookRef &lt;span style="color: #002200;"&gt;=&lt;/span&gt; ABAddressBookCreate&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
CFArrayRef allContacts &lt;span style="color: #002200;"&gt;=&lt;/span&gt; ABAddressBookCopyArrayOfAllPeople&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;addressBookRef&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
&lt;span style="color: #11740a; font-style: italic;"&gt;// upload this to server and do something really nasty&lt;/span&gt;
CFRelease&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;addressBookRef&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
CFRelease&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;allContacts&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There is no prompt whatsoever shown by the system.&lt;/p&gt;
&lt;span id="What_should_Apple_do"&gt;&lt;h3&gt;What should Apple do?&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Show an access control dialog when an application makes a request to access address book. Probably from the version first iteration of iOS, you get a prompt when any app (including Apple&amp;#8217;s own apps) requests for your location or for your unique device token for sending you notifications. Apple should extend this feature to programatic access of your contacts and calendar as well (EventKit.framework).&lt;/p&gt;
&lt;p&gt;Personally, I&amp;#8217;m least bothered about apps stealing my contacts. I&amp;#8217;ll be more bothered if an app steals my events. Let me give you an example.&lt;/p&gt;
&lt;p&gt;Imagine that I have a meeting with a client ABC from 10 AM to 11 AM on Feb 10th at their office, One Marina Boulevard, Singapore. Just imagine what all can be done when a company knows this information. They can stalk me. They can rob my home when I&amp;#8217;m not there. They can sell this information to a &amp;#8220;order a pizza&amp;#8221; guy who could cold-call me during lunch time to up-sell his pizza. Well, most of these don&amp;#8217;t really happen. But they _can_ technically happen.&lt;/p&gt;
&lt;p&gt;Reading your calendar to know your upcoming events is also few lines of code&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;EKEventStore &lt;span style="color: #002200;"&gt;*&lt;/span&gt;store &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;EKEventStore alloc&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; init&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #400080;"&gt;NSPredicate&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;eventPredicate &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;store predicateForEventsWithStartDate&lt;span style="color: #002200;"&gt;:&lt;/span&gt;startDate endDate&lt;span style="color: #002200;"&gt;:&lt;/span&gt;endDate calendars&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #a61390;"&gt;nil&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #400080;"&gt;NSArray&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;matchingEvents &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;store eventsMatchingPredicate&lt;span style="color: #002200;"&gt;:&lt;/span&gt;eventPredicate&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #11740a; font-style: italic;"&gt;// upload this to server and do something really nasty&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;span id="How_can_you_help"&gt;&lt;h3&gt;How can you help?&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;If you are a iOS developer, open bugreport.apple.com and file a bug report like this radar &lt;a href="http://openradar.appspot.com/10824178"&gt;10824178&lt;/a&gt;. Duplicate this. The more a bug gets duplicated, the more faster it reaches Apple.&lt;/p&gt;
&lt;p&gt;If you are an iDevice user, remember that there is no free lunch. When a company makes a product free, &lt;strong&gt;YOU&lt;/strong&gt; are their product. Be cautious when a app requests for any additional information like your location or push notifications. There are plenty of apps that I know, that use push notifications purely for marketing. Marketing emails in Web 2.0 era is slowly being transformed to push notifications in this mobile dominated decade. Sad part is that, there is no way to unsubscribe from those annoying push notifications apart from deleting the app.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s all hope that Apple addresses this issue at the earliest before something really _bad_ happens.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1504_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1504?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1504_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1504&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Farticles%2Fsome-thoughts-on-ios-and-your-privacy-address-book%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;No related posts.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/wdiIH9x88rvvMXtlq5ZQ4SFOtRw/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wdiIH9x88rvvMXtlq5ZQ4SFOtRw/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/wdiIH9x88rvvMXtlq5ZQ4SFOtRw/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wdiIH9x88rvvMXtlq5ZQ4SFOtRw/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/q-P_VDlXVcM" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/articles/some-thoughts-on-ios-and-your-privacy-address-book/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">4</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/articles/some-thoughts-on-ios-and-your-privacy-address-book/</feedburner:origLink></entry><entry><title type="text">iOS Tutorial: Image Cache and Loading Thumbnails using MKNetworkKit</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/qZ24l_17NS8/" /><category term="Coding" /><category term="arc" /><category term="cache" /><category term="flickr" /><category term="image" /><category term="ios 5" /><category term="mknetworkkit" /><author><name>Mugunth Kumar</name></author><updated>2012-01-21T20:30:29-08:00</updated><id>http://blog.mugunthkumar.com/?p=1485</id><summary type="html">If you have been following me on Twitter or reading MKBlog, you would already be knowing about MKNetworkKit. I wrote a introductory post on MKNetworkKit couple of months ago and later explained in a more detailed post on how to use it in other sophisticated scenarios. From feedback so far, Image Caching was one aspect [...]
Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/ios-tutorial-advanced-networking-with-mknetworkkit/' rel='bookmark' title='iOS Tutorial: Advanced Networking with MKNetworkKit'&gt;iOS Tutorial: Advanced Networking with MKNetworkKit&lt;/a&gt; &lt;small&gt;Couple of weeks ago, I wrote a clean, fast networking...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you have been &lt;a href="http://twitter.com/mugunthkumar"&gt;following me on Twitter&lt;/a&gt; or reading MKBlog, you would already be knowing about MKNetworkKit.&lt;/p&gt;
&lt;p&gt;I wrote a &lt;a href="http://blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/"&gt;introductory post on MKNetworkKit&lt;/a&gt; couple of months ago and later explained in a &lt;a href="http://blog.mugunthkumar.com/coding/ios-tutorial-advanced-networking-with-mknetworkkit/"&gt;more detailed post&lt;/a&gt; on how to use it in other sophisticated scenarios.&lt;/p&gt;
&lt;div class='toc toc'&gt;
&lt;h2&gt;Contents&lt;/h2&gt;
&lt;ul class='toc-odd level-1'&gt;
		&lt;ul class='toc-even level-2'&gt;
			&lt;li&gt;
				&lt;a href="#Step_1:_Create_a_Flickr_Engine"&gt;Step 1: Create a Flickr Engine&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Step_2:_Create_a_custom_cache_directory_for_storing_the_cached_Flickr_thumbanils"&gt;Step 2: Create a custom cache directory for storing the cached Flickr thumbanils&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Step_3:_Write_a_method_to_list_flickr_images_for_a_specified_tag"&gt;Step 3: Write a method to list flickr images for a specified tag&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Step_4:_Create_a_custom_table_view_cell_for_loading_flickr_images"&gt;Step 4: Create a custom table view cell for loading flickr images&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Step_5:_Clear_previously_loaded_images_if_the_cell_will_be_reused"&gt;Step 5: Clear previously loaded images if the cell will be reused&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Step_6:_Fade_in_thumbnails_like_the_Apple_trailers_app"&gt;Step 6: Fade in thumbnails like the Apple trailers app&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
	&lt;li&gt;
		&lt;a href="#Source_Code"&gt;Source Code&lt;/a&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class='toc-end'&gt;&amp;nbsp;&lt;/div&gt;
&lt;p&gt;From feedback so far, Image Caching was one aspect of MKNetworkKit that developers didn&amp;#8217;t understand pretty well. In this post, I&amp;#8217;ll try to explain how to use MKNetworkKit for image caching and loading thumbnails.&lt;br /&gt;
Thumbnails are often used in iOS apps to load friend&amp;#8217;s avatar pictures from a Facebook feed or flickr thumbnails for a given tag and in many similar cases.&lt;/p&gt;
&lt;p&gt;MKNetworkEngine makes it a breeze to add this feature into your app. What not? With MKNetworkKit, you will even know if the response image is from cache or loaded for the first time. Using this information, you can &amp;#8220;fade in&amp;#8221; your thumbnails when you load the images for the first time (like in Apple&amp;#8217;s &lt;a href="http://itunes.apple.com/us/app/itunes-movie-trailers/id471966214?mt=8"&gt;iTunes Movie Trailers&lt;/a&gt; app).&lt;/p&gt;
&lt;p&gt;The completed example looks like this.&lt;/p&gt;
&lt;div class="wp-caption aligncenter" style="width: 331px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="iOS Simulator.png" src="http://blog.mugunthkumar.com/wp-content/uploads/iOS-Simulator.png" alt="IOS Simulator" width="321" height="600" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Screenshot showing images loaded asynchronously using MKNetworkKit&lt;/p&gt;&lt;/div&gt;
&lt;p style="text-align: left;"&gt;Having said that, lets get our hands dirty with some real code. In this example, I&amp;#8217;ll show you how to load images from Flickr on a table view controller asynchronously.&lt;/p&gt;
&lt;span id="Step_1:_Create_a_Flickr_Engine"&gt;&lt;h3&gt;Step 1: Create a Flickr Engine&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Easy peasy. Create a subclass of MKNetworkEngine and let&amp;#8217;s name it as &amp;#8220;FlickrEngine&amp;#8221;. Initialize your flickr engine with api.flickr.com as hostname in your application delegate.&lt;/p&gt;
&lt;span id="Step_2:_Create_a_custom_cache_directory_for_storing_the_cached_Flickr_thumbanils"&gt;&lt;h3&gt;Step 2: Create a custom cache directory for storing the cached Flickr thumbanils&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Override cacheDirectoryName and return a custom directory for storing the cached thumbnails.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; cacheDirectoryName &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #400080;"&gt;NSArray&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;paths &lt;span style="color: #002200;"&gt;=&lt;/span&gt; NSSearchPathForDirectoriesInDomains&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;NSCachesDirectory, NSUserDomainMask, &lt;span style="color: #a61390;"&gt;YES&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style="color: #400080;"&gt;NSString&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;documentsDirectory &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;paths objectAtIndex&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #2400d9;"&gt;0&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
    &lt;span style="color: #400080;"&gt;NSString&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;cacheDirectoryName &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;documentsDirectory stringByAppendingPathComponent&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;FlickrImages&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
    &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; cacheDirectoryName;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This step is optional. But, since thumbnails can easily occupy precious disk space, you might want to clear them at periodic intervals. MKNetworkEngine provides a handy method (emptyCache) to empty the cache directory for a specific engine. The default implementation of this method removes all files within the cache directory of that engine. If you don&amp;#8217;t override cacheDirectoryName and provide a distinct cache directory for your engine, you will end up emptying the shared cache directory, when you call emptyCache.&lt;/p&gt;
&lt;span id="Step_3:_Write_a_method_to_list_flickr_images_for_a_specified_tag"&gt;&lt;h3&gt;Step 3: Write a method to list flickr images for a specified tag&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;By now, you already know that creating a network request using MKNetworkKit is a no-brainer. The following shows how to create a request for loading images for a given tag.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; imagesForTag&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; tag onCompletion&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;FlickrImagesResponseBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; imageURLBlock onError&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;MKNKErrorBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; errorBlock &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    MKNetworkOperation &lt;span style="color: #002200;"&gt;*&lt;/span&gt;op &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self operationWithPath&lt;span style="color: #002200;"&gt;:&lt;/span&gt;FLICKR_IMAGE_URL&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;tag urlEncodedString&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;op onCompletion&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;MKNetworkOperation &lt;span style="color: #002200;"&gt;*&lt;/span&gt;completedOperation&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style="color: #400080;"&gt;NSDictionary&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;response &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;completedOperation responseJSON&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
        imageURLBlock&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;response objectForKey&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;photos&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; objectForKey&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;photo&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt; onError&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSError&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;error&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        errorBlock&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;error&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self enqueueOperation&lt;span style="color: #002200;"&gt;:&lt;/span&gt;op&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The FLICKR_IMAGE_URL macro is defined as&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #6e371a;"&gt;#define FLICKR_IMAGE_URL(__TAG__) [NSString stringWithFormat:@&amp;quot;services/rest/?method=flickr.photos.search&amp;amp;amp;api_key=%@&amp;amp;amp;tags=%@&amp;amp;amp;per_page=200&amp;amp;amp;format=json&amp;amp;amp;nojsoncallback=1&amp;quot;, FLICKR_KEY, __TAG__]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that, the host name api.flickr.com gets prefixed automatically when you create operations on this engine.&lt;/p&gt;
&lt;p&gt;You should generate a new flickr api key and replace it in the FLICKR_KEY macro. You can create one for free &lt;a href="http://www.flickr.com/services/apps/create/apply"&gt;here.&lt;/a&gt; (For running the example, you can use my key)&lt;/p&gt;
&lt;span id="Step_4:_Create_a_custom_table_view_cell_for_loading_flickr_images"&gt;&lt;h3&gt;Step 4: Create a custom table view cell for loading flickr images&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;In this custom cell, write a method setFlickrData: that updates the cell from the dictionary you receive by invoking the flickr REST API&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; setFlickrData&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSDictionary&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; thisFlickrImage &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    self.titleLabel.text &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;thisFlickrImage objectForKey&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
	self.authorNameLabel.text &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;thisFlickrImage objectForKey&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;owner&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
    self.loadingImageURLString &lt;span style="color: #002200;"&gt;=&lt;/span&gt;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSString&lt;/span&gt; stringWithFormat&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;http://farm%@.static.flickr.com/%@/%@_%@_s.jpg&amp;quot;&lt;/span&gt;,
     &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;thisFlickrImage objectForKey&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;farm&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;, &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;thisFlickrImage objectForKey&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;,
     &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;thisFlickrImage objectForKey&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;, &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;thisFlickrImage objectForKey&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;secret&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
    self.imageLoadingOperation &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;ApplicationDelegate.flickrEngine imageAtURL&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt; URLWithString&lt;span style="color: #002200;"&gt;:&lt;/span&gt;self.loadingImageURLString&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;
                                    onCompletion&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIImage &lt;span style="color: #002200;"&gt;*&lt;/span&gt;fetchedImage, &lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;url, &lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt; isInCache&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
                                        &lt;span style="color: #a61390;"&gt;if&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.loadingImageURLString isEqualToString&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;url absoluteString&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
                                                self.thumbnailImage.image &lt;span style="color: #002200;"&gt;=&lt;/span&gt; fetchedImage;
                                    &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;&lt;p&gt;Tip: Avoid setting the individual labels of a table view cell in the cellForRowAtIndexPath: method. It makes the cell less portable across your other view controllers.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Carefully note the use of the variable self.loadingImageURLString. If you don&amp;#8217;t save the loading image&amp;#8217;s URL in an ivar, your images will continue to be updated when the previous operation completes. To circumvent this, either cancel the operation when a cell is reused, or check if the returned URL is the original URL that was loaded for this cell (by storing it in ivar).&lt;/p&gt;
&lt;p&gt;As on &lt;a href="https://github.com/MugunthKumar/MKNetworkKit/commit/b9ba2d6501b498e837abf49cb999dbbd67b30a4f"&gt;this commit&lt;/a&gt;, MKNetworkEngine&amp;#8217;s imageAtURL method will return you the actual operation created. You should retain this and cancel it when not necessary.&lt;/p&gt;
&lt;span id="Step_5:_Clear_previously_loaded_images_if_the_cell_will_be_reused"&gt;&lt;h3&gt;Step 5: Clear previously loaded images if the cell will be reused&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;You should clear previously loaded images by overriding prepareForReuse method. It&amp;#8217;s a one-liner.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; prepareForReuse &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    self.thumbnailImage.image &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #a61390;"&gt;nil&lt;/span&gt;;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.imageLoadingOperation cancel&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you don&amp;#8217;t write this, you will see old images on the cell while the new image is being loaded.&lt;br /&gt;
Instead of &amp;#8220;nil&amp;#8221; you can also show a default placeholder image here.&lt;/p&gt;
&lt;p&gt;You should also consider canceling the old imageLoadingOperation so as to load the latest visible cells faster. If you don&amp;#8217;t cancel the operation, when the user scrolls fast to the bottom of the list, the engine loads all the images from the first cell (including images for cells that are now hidden and reused) and there by slowing down the image load operation for the currently visible cell. You can test this from the code by commenting it out and checking the performance.&lt;/p&gt;
&lt;span id="Step_6:_Fade_in_thumbnails_like_the_Apple_trailers_app"&gt;&lt;h3&gt;Step 6: Fade in thumbnails like the Apple trailers app&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkEngine&amp;#8217;s imageAtURL method returns the image in a block method. The block method, onCompletion looks like this.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIImage &lt;span style="color: #002200;"&gt;*&lt;/span&gt;fetchedImage, &lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;url, &lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt; isInCache&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
                                        &lt;span style="color: #a61390;"&gt;if&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.loadingImageURLString isEqualToString&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;url absoluteString&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
                                                self.thumbnailImage.image &lt;span style="color: #002200;"&gt;=&lt;/span&gt; fetchedImage;
                                    &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If the variable isInCache is false, you can &amp;#8220;fade in&amp;#8221; the image so as to add a nice UI touch to your app. The following code block illustrates this.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIImage &lt;span style="color: #002200;"&gt;*&lt;/span&gt;fetchedImage, &lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;url, &lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt; isInCache&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
                                        &lt;span style="color: #a61390;"&gt;if&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.loadingImageURLString isEqualToString&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;url absoluteString&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
                                            &lt;span style="color: #a61390;"&gt;if&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;isInCache&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
                                                self.thumbnailImage.image &lt;span style="color: #002200;"&gt;=&lt;/span&gt; fetchedImage;
                                            &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt; &lt;span style="color: #a61390;"&gt;else&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
                                                UIImageView &lt;span style="color: #002200;"&gt;*&lt;/span&gt;loadedImageView &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIImageView alloc&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; initWithImage&lt;span style="color: #002200;"&gt;:&lt;/span&gt;fetchedImage&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
                                                loadedImageView.frame &lt;span style="color: #002200;"&gt;=&lt;/span&gt; self.thumbnailImage.frame;
                                                loadedImageView.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #2400d9;"&gt;0&lt;/span&gt;;
                                                &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.contentView addSubview&lt;span style="color: #002200;"&gt;:&lt;/span&gt;loadedImageView&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
                                                &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIView animateWithDuration&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #2400d9;"&gt;0.4&lt;/span&gt;
                                                                 animations&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;
                                                 &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
                                                     loadedImageView.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #2400d9;"&gt;1&lt;/span&gt;;
                                                     self.thumbnailImage.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #2400d9;"&gt;0&lt;/span&gt;;
                                                 &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
                                                                 completion&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt; finished&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;
                                                 &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
                                                     self.thumbnailImage.image &lt;span style="color: #002200;"&gt;=&lt;/span&gt; fetchedImage;
                                                     self.thumbnailImage.alpha &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #2400d9;"&gt;1&lt;/span&gt;;
                                                     &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;loadedImageView removeFromSuperview&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
                                                 &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
                                            &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
                                        &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
                                    &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;span id="Source_Code"&gt;&lt;h2&gt;Source Code&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;The complete source code is available as a demo on &lt;a href="https://github.com/MugunthKumar/MKNetworkKit"&gt;MKNetworkKit&amp;#8217;s Github repository&lt;/a&gt;.&lt;br /&gt;
&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1485_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1485?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1485_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1485&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fios-tutorial-image-cache-and-loading-thumbnails-using-mknetworkkit%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/ios-tutorial-advanced-networking-with-mknetworkkit/' rel='bookmark' title='iOS Tutorial: Advanced Networking with MKNetworkKit'&gt;iOS Tutorial: Advanced Networking with MKNetworkKit&lt;/a&gt; &lt;small&gt;Couple of weeks ago, I wrote a clean, fast networking...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KHrVZO6lxMutyZJ7Sx0cFk_pjR0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KHrVZO6lxMutyZJ7Sx0cFk_pjR0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KHrVZO6lxMutyZJ7Sx0cFk_pjR0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KHrVZO6lxMutyZJ7Sx0cFk_pjR0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/qZ24l_17NS8" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/coding/ios-tutorial-image-cache-and-loading-thumbnails-using-mknetworkkit/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">12</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/coding/ios-tutorial-image-cache-and-loading-thumbnails-using-mknetworkkit/</feedburner:origLink></entry><entry><title type="text">Migrating your code to Objective-C ARC</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/zTyi6w_9bMk/" /><category term="Articles" /><category term="Featured Articles" /><category term="arc" /><category term="ios 4" /><category term="ios5" /><category term="lion" /><category term="objective c" /><category term="programming" /><category term="snow leopard" /><author><name>Mugunth Kumar</name></author><updated>2011-12-23T15:00:08-08:00</updated><id>http://blog.mugunthkumar.com/?p=1412</id><summary type="html">Recently, Apple introduced several new developer stuff including Xcode 4, ARC, LLVM Compiler 3.0 and iOS 5. From some of the questions on Stack overflow, I could understand that, most of the ARC related confusions arise due to the fact that, developers don&amp;#8217;t know if &amp;#8220;ABC&amp;#8221; is a feature/restriction of LLVM 3.0 or iOS 5 [...]
Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/mkstorekit-4-0-supporting-auto-renewable-subscriptions/' rel='bookmark' title='MKStoreKit 4.0 &amp;#8211; Supporting Auto Renewable Subscriptions'&gt;MKStoreKit 4.0 &amp;#8211; Supporting Auto Renewable Subscriptions&lt;/a&gt; &lt;small&gt;MKStoreKit started off in a pet project a couple of...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;Recently, Apple introduced several new developer stuff including Xcode 4, ARC, LLVM Compiler 3.0 and iOS 5. From some of the questions on Stack overflow, I could understand that, most of the ARC related confusions arise due to the fact that, developers don&amp;#8217;t know if &amp;#8220;ABC&amp;#8221; is a feature/restriction of LLVM 3.0 or iOS 5 or ARC.&lt;/p&gt;
&lt;p&gt;Retain cycles, auto-release pools, @autorelease blocks, oh man! So many new things? What am I going to do? You are right. ARC, or Objective-C Automatic Reference Counting is almost &lt;a href="http://blog.mugunthkumar.com/articles/random-thoughts-on-ipad/"&gt;as magical as the iPad&lt;/a&gt;. No really.&lt;/p&gt;
&lt;p&gt;In this post, I&amp;#8217;ve made an attempt to demystify the air around this. Before starting, I&amp;#8217;ll have to warn you that, this is a fairly long post. If you are too bored, Instapaper this article and read it later. But, hopefully, at the end of this, I believe, you will have a better understanding on how ARC works and be able to work around the innumerable errors it spits out when you convert your project.&lt;/p&gt;
&lt;p&gt;Having said that, let&amp;#8217;s get started.&lt;/p&gt;
&lt;div class='toc toc'&gt;
&lt;h2&gt;Contents&lt;/h2&gt;
&lt;ul class='toc-odd level-1'&gt;
	&lt;li&gt;
		&lt;a href="#What_is_ARC"&gt;What is ARC&lt;/a&gt;
		&lt;ul class='toc-even level-2'&gt;
&lt;ul class='toc-odd level-3'&gt;
			&lt;li&gt;
				&lt;a href="#Problems_with_the_current_model."&gt;Problems with the current model.&lt;/a&gt;
				&lt;ul class='toc-even level-4'&gt;
					&lt;li&gt;
						&lt;a href="#Garbage_collection"&gt;Garbage collection&lt;/a&gt;
					&lt;/li&gt;
					&lt;li&gt;
						&lt;a href="#Reference_Counting"&gt;Reference Counting&lt;/a&gt;
					&lt;/li&gt;
					&lt;li&gt;
						&lt;a href="#Automatic_Reference_Counting"&gt;Automatic Reference Counting&lt;/a&gt;
					&lt;/li&gt;
				&lt;/ul&gt;
&lt;/ul&gt;
			&lt;li&gt;
				&lt;a href="#Compiler_level_feature"&gt;Compiler level feature&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Also_a_run_time_feature"&gt;Also a run time feature&lt;/a&gt;
				&lt;ul class='toc-odd level-3'&gt;
					&lt;li&gt;
						&lt;a href="#ARC_Ownership_qualifiers"&gt;ARC Ownership qualifiers&lt;/a&gt;
					&lt;/li&gt;
				&lt;/ul&gt;
			&lt;li&gt;
				&lt;a href="#ARC_knows_more_Objective-C_than_you"&gt;ARC knows more Objective-C than you&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Toll-free_bridging"&gt;Toll-free bridging&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
	&lt;li&gt;
		&lt;a href="#How_does_ARC_work_internally"&gt;How does ARC work internally?&lt;/a&gt;
		&lt;ul class='toc-even level-2'&gt;
			&lt;li&gt;
				&lt;a href="#ARC_front_end"&gt;ARC front end&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#ARC_optimizer"&gt;ARC optimizer&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
	&lt;li&gt;
		&lt;a href="#The_actual_Migration_using_Xcode_4.2"&gt;The actual Migration using Xcode 4.2&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#Common_ARC_migration_errors"&gt;Common ARC migration errors&lt;/a&gt;
		&lt;ul class='toc-even level-2'&gt;
			&lt;li&gt;
				&lt;a href="#Cast_of_Objective-C_pointer_to_C_Pointer_type"&gt;Cast of Objective-C pointer to C Pointer type&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#performSelector_may_cause_a_leak_because_its_selector_is_unknown"&gt;performSelector may cause a leak because its selector is unknown&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Receiver_type__doesnt_declare_the_method_with_selector_"&gt;Receiver type "*" doesn't declare the method with selector "*"&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Common_workarounds_that_you_use_in_ARC_on_code_that_otherwise_looks_normal"&gt;Common workarounds that you use in ARC on code that otherwise looks normal&lt;/a&gt;
				&lt;ul class='toc-odd level-3'&gt;
					&lt;li&gt;
						&lt;a href="#Capturing__strongly_is_likely_to_lead_to_a_retain_cycle"&gt;Capturing "*" strongly is likely to lead to a retain cycle&lt;/a&gt;
					&lt;/li&gt;
					&lt;li&gt;
						&lt;a href="#Avoiding_retain_cycles_using___block"&gt;Avoiding retain cycles using __block&lt;/a&gt;
					&lt;/li&gt;
				&lt;/ul&gt;
&lt;/ul&gt;
			&lt;li&gt;
				&lt;a href="#That_last_question"&gt;That last question&lt;/a&gt;
				&lt;ul class='toc-even level-2'&gt;
					&lt;li&gt;
						&lt;a href="#When_should_you_migrate"&gt;When should you migrate?&lt;/a&gt;
					&lt;/li&gt;
				&lt;/ul&gt;
			&lt;li&gt;
				&lt;a href="#Where_to_go_from_here"&gt;Where to go from here?&lt;/a&gt;
			&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class='toc-end'&gt;&amp;nbsp;&lt;/div&gt;
&lt;span id="What_is_ARC"&gt;&lt;h2&gt;What is ARC&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;ARC is a feature of the new LLVM 3.0 compiler that helps you to write code without worrying &lt;strong&gt;&lt;em&gt;much&lt;/em&gt;&lt;/strong&gt; about memory management. Memory management can be broadly classified into two, garbage collected and reference counted models. Before going to the details, let’s briefly discuss these two models and understand why ARC is even needed.&lt;/p&gt;
&lt;span id="Problems_with_the_current_model."&gt;&lt;h4&gt;Problems with the current model.&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;The current memory model we use in Objective-C is manual reference counting on iOS and Garbage collection on Mac.&lt;/p&gt;
&lt;p&gt;There are certain problems with both these memory models which probably was the reason why ARC was developed.&lt;/p&gt;
&lt;span id="Garbage_collection"&gt;&lt;h5&gt;Garbage collection&lt;/h5&gt;&lt;/span&gt;
&lt;p&gt;Garbage collection is a higher level language feature probably introduced in Java (or technically, Java Virtual Machine) and implemented in a variety of other programming platforms including Microsoft’s Common Language Runtime. While Garbage collection worked well for higher level languages, Objective-C, which is still C under the hood, didn’t really fly high. Pointers (or rather references) in other languages like Java were actually objects that managed retain count and automatically releases itself when the count reaches zero. One of the design goals of C was to be optimized for performance and not “easy of use”. While pointer objects (read &lt;a href="http://en.wikipedia.org/wiki/Smart_pointer"&gt;smart pointers&lt;/a&gt;) are great object oriented abstractions, they have an adverse effect on the performance of the code and since Objective-C was intended primarily for native programming where developers are used to use pointers, pointers within a structure, pointer to a pointer (for dereferencing a out parameter), it was just too difficult to introduce something like a smart pointer that would require a lot of mindset change from the developers who prefer a deterministic memory management model (Reference counting) over a non-deterministic memory management model (Garbage collection). Nevertheless, GC (&lt;a href="http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Generational_GC_.28ephemeral_GC.29"&gt;Generational GC&lt;/a&gt;) was introduced in Objective-C 2.0 for Mac. While Generational GC doesn&amp;#8217;t suffer from &amp;#8220;Stop the world&amp;#8221; issues like the mark and sweep alogrithm, they don&amp;#8217;t collect every released variable and an occasional mark and sweep collection is still needed.&lt;/p&gt;
&lt;span id="Reference_Counting"&gt;&lt;h5&gt;Reference Counting&lt;/h5&gt;&lt;/span&gt;
&lt;p&gt;The memory management model used in iOS is called as reference counting model, or more precisely, manual reference counting.&lt;br /&gt;
In manual reference counting model, you as a developer, have to deallocate every object you allocated. When you don’t do this, you either leak memory or over release it, causing a crash. While that counting sounds easy, Most of the memory leaks happen when you transfer ownership of objects across scope boundaries. That’s a creator method that allocates an object for you and expects the caller to deallocate it. To circumvent this problem, Objective-C introduced a concept called autorelease. auto-released variables are added to the auto-release pool and are released at the end of the runloop. While this sounds too good, auto-release pools do incur an additional overhead.&lt;/p&gt;
&lt;p&gt;For example, comparing the two code blocks,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #400080;"&gt;NSDictionary&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;dict &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSDictionary&lt;/span&gt; alloc&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; init&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// do something with the dictionary here&lt;/span&gt;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// I'm done with the dictionary, I don't need it anymore&lt;/span&gt;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;dict release&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// more code&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #400080;"&gt;NSDictionary&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;dict &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSDictionary&lt;/span&gt; dictionary&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;; &lt;span style="color: #11740a; font-style: italic;"&gt;// auto-released object&lt;/span&gt;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// do something with the dictionary here&lt;/span&gt;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// I'm done with the dictionary, I don't need it anymore&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// more code&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;the first block is an example of optimized use of memory where as the second depends on auto-release pools. While this block of code doesn’t really incur significant memory overhead, code like these slowly adds together and makes your reference counted model heavily dependent on auto-release pools. That is, objects that you know could be deallocated, will still linger around in the auto-release pool for a little longer.&lt;/p&gt;
&lt;span id="Automatic_Reference_Counting"&gt;&lt;h5&gt;Automatic Reference Counting&lt;/h5&gt;&lt;/span&gt;
&lt;p&gt;Say hello to ARC. ARC is a compiler feature that auto inserts retain and release for you. So in the first code block of the above example, you no longer have to write the release method and ARC auto-inserts for you before compilation.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
    &lt;span style="color: #400080;"&gt;NSDictionary&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;dict &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSDictionary&lt;/span&gt; alloc&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; init&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// do something with the dictionary here&lt;/span&gt;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// I'm done with the dictionary, I don't need it anymore&lt;/span&gt;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;dict release&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;; &lt;span style="color: #11740a; font-style: italic;"&gt;// ARC inserts this code for you.&lt;/span&gt;
    &lt;span style="color: #11740a; font-style: italic;"&gt;// more code&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When you create an autoreleased object, like in the second block of code, ARC compiler is clever enough not to add a release call. Sound great, so how should I go about doing this ARC thing? Just delete all release/retain codes and pray? Unfortunately, it isn&amp;#8217;t that easy. ARC is not just some auto insert or macro expander kind of tool. &lt;strong&gt;It forces you to think in terms of object graphs instead of memory allocation, retain or release.&lt;/strong&gt; Let&amp;#8217;s delve a little deeper into ARC.&lt;/p&gt;
&lt;span id="Compiler_level_feature"&gt;&lt;h3&gt;Compiler level feature&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;ARC is a compiler level feature. I repeat. ARC IS A COMPILER LEVEL FEATURE. This means, when you use ARC, you don’t have to worry about upgrading your deployment target and so on. However, only the latest LLVM 3.0 compiler supports ARC. If you are still stuck with GCC, you are out of luck. (Meh!) Some more points that you should know about ARC are,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ARC is backward compatible with libraries and framework compiled with under non-ARC.&lt;/li&gt;
&lt;li&gt;ARC can be used within your project on a file-by-file basis. So you can mix and match ARC code with non-ARC code.&lt;/li&gt;
&lt;li&gt;You can also integrate ARC compiled libraries into your project that doesn’t use ARC and vice-versa.&lt;/li&gt;
&lt;li&gt;You use a &lt;strong&gt;compiler switch&lt;/strong&gt; to turn ARC on and off.&lt;/li&gt;
&lt;li&gt;(The keyword here is compiler switch)&lt;/li&gt;
&lt;li&gt;You can also set the complete target to build with ARC by default (and use non-ARC compiler only when instructed so.) This is shown in the illustration below.&lt;/li&gt;
&lt;li&gt;&lt;img title="ARC - Xcode.png" src="http://blog.mugunthkumar.com/wp-content/uploads/ARC-Xcode.png" alt="ARC  Xcode" width="600" height="229" border="0" /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The two main compiler switches that you would often use are when you build your application with a third party library that is not ARC compliant and vice versa, are&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;-f&lt;strong&gt;no-objc-arc&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;-f&lt;strong&gt;objc-arc&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;-f is the switch and &lt;strong&gt;no-objc-arc&lt;/strong&gt; and &lt;strong&gt;objc-arc&lt;/strong&gt; are the options that you are turning on. As evident from the names, the first one turns off ARC and the second turns on.&lt;/p&gt;
&lt;p&gt;For example, if your application is ARC enabled but a third party library is not, you use the first switch &lt;strong&gt;-fno-objc-arc&lt;/strong&gt; to exclude the third party library. Conversely, if your application is not yet ARC enabled (gasp!) but the third party library you are integrating is, you use the second switch &lt;strong&gt;-fobjc-arc&lt;/strong&gt; You add these flags to the project from the Build phases tab as shown below.&lt;img title="Xcode-2-1.png" src="http://blog.mugunthkumar.com/wp-content/uploads/Xcode-2-1.png" alt="Xcode 2 1" width="600" height="374" border="0" /&gt;&lt;/p&gt;
&lt;span id="Also_a_run_time_feature"&gt;&lt;h3&gt;Also a run time feature&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Wait! You just told me (and repeated) that ARC is a compiler level feature? Now what? Sorry, I hear you, but, unfortunately, things aren&amp;#8217;t that easy and it doesn&amp;#8217;t just stop here. ARC also backs up on a runtime feature called &lt;em&gt;zero-ing weak references&lt;/em&gt;. Oh, damn, another keyword! I should have introduced this before. But that’s ok. We will revisit about the run-time dependency of ARC, a little later in this post.&lt;/p&gt;
&lt;span id="ARC_Ownership_qualifiers"&gt;&lt;h4&gt;ARC Ownership qualifiers&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;As I showed you earlier, ARC automatically inserts releases and retains in your code in a pre-compilation step. But for ARC to know when to release your objects and when to retain them, you need to somehow tell the life of your variables. You use ownership qualifiers for that. A strong understanding of ownerships is vital to understand and use ARC properly. Once you understand this concept, you will be thinking in terms of object graphs instead of retain/release. Secondly, when you use ARC, all variables local or ivars are initialized to nil automatically for you. This means, there is little chance of having a dangling reference in your application.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;__strong&lt;/li&gt;
&lt;li&gt;__weak&lt;/li&gt;
&lt;li&gt;__unsafe_unretained&lt;/li&gt;
&lt;li&gt;__autoreleasing&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first qualifier, __strong, is the default and you might not even be using this explicitly. It is use to tell the ARC compiler that, the declared variable &amp;#8220;owns&amp;#8221; the reference. The opposite of this is __weak, which tells the ARC compiler that the declared variable doesn&amp;#8217;t own the reference.&lt;/p&gt;
&lt;p&gt;The __weak is &lt;em&gt;synonymous&lt;/em&gt; to the &amp;#8220;assign&amp;#8221; modifier. You normally use assign modifier for IBOutlets and delegates. Under ARC, this is replaced with __weak. However, there is a caveat. __weak requires you to deploy the app on a runtime that supports &lt;em&gt;zero-ing weak references&lt;/em&gt;. This includes, iOS 5 and Lion. Snow Leopard and older operating systems or iOS 4 and older operating systems don&amp;#8217;t support zero-ing weak references. This obviously means you cannot use __weak ownership modifiers if you plan to deploy to older operating systems. Fret not. ARC includes another ownership qualifier, __unsafe_unretained that is synonymous to __weak, except that when the pointer is de-referenced, it is not set to nil, but remains dangling. A while ago, I told something about zero-ing weak references? When the runtime supports zero-ing weak references, your __weak variables are automatically set to nil when they are released. This is the only feature that requires a higher deployment target (iOS 5/Lion). Otherwise, you are good to deploy on iOS 4/Snow Leopard.&lt;/p&gt;
&lt;p&gt;A couple other important things to know about __weak vs __unsafe_unretained is that, the compiler doesn&amp;#8217;t allow you to use __weak when your deployment target is set to a operating system that doesn&amp;#8217;t support zero-ing weak references. The Convert to Objective-C ARC wizard uses __weak only when your deployment target supports zero-ing weak references. So if your deployment target is iOS 4, the Objective-C convert ion wizard will replace assign modifiers with __unsafe_unretained instead of __weak.&lt;/p&gt;
&lt;p&gt;The last ownership qualifier, __auto_releasing is used mostly when passing a reference to a function for writing out. You would use this in places where you normally use pointer indirection like returning a NSError object via an out parameter.&lt;/p&gt;
&lt;p&gt;Properties in your header file can also have the above ownership qualifiers except the __auto_releasing. When applied to properties, ARC automatically generates the correct code in dealloc to release them when the object dies.&lt;/p&gt;
&lt;p&gt;Lastly, and more importantly, all of ARC managed &lt;strong&gt;objects&lt;/strong&gt; are initialized to nil when they are created. So, again, no more dangling pointers because you forgot a initialize statement. However, do note that this initialization doesn&amp;#8217;t initialize primitive data types. So a declaration like,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #a61390;"&gt;int&lt;/span&gt; a;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;might contain a garbage value for a.&lt;/p&gt;
&lt;p&gt;Whew! That&amp;#8217;s pretty taxing. Take a break. We just started.&lt;/p&gt;
&lt;span id="ARC_knows_more_Objective-C_than_you"&gt;&lt;h3&gt;ARC knows more Objective-C than you&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;ARC also taps into a the Objective-C language naming conventions and infers the ownership of the returned object.&lt;/p&gt;
&lt;p&gt;In Objective-C, a method that stats with any one of the following prefix,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;alloc,&lt;/li&gt;
&lt;li&gt;copy,&lt;/li&gt;
&lt;li&gt;mutableCopy and&lt;/li&gt;
&lt;li&gt;new&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;are considered to be transferring ownership of the returned object to the caller.&lt;br /&gt;
This means, in your application, when you create a method, ARC automatically infers whether to return a autoreleased object or a +1 retained object from your method name. In fact, in most cases, instead of returning auto-release objects, ARC just inserts a manual release in the calling code, automatically for you. However, there is a small caveat. Let&amp;#8217;s assume that you have a method that starts with &amp;#8220;copy&amp;#8221;, as in&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; copyRightString;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;ARC assumes that it would transfer the ownership of the returned string to the caller and inserts a release automatically. Everything works well, if both the called method and the calling method are compiled using ARC.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;But&lt;/em&gt;&lt;/strong&gt; if your &amp;#8220;copyRightString&amp;#8221; method is in a third party library that isn&amp;#8217;t compiled with ARC, you will over-release the returned string. This is because, on the calling code, ARC compiler inserts a release to balance out the retain count bumped up by the &amp;#8220;copy&amp;#8221; method. Conversely, if the third party library is compiled with ARC and your method isn&amp;#8217;t, you will have a memory leak. You can however override this behavior by adding one of the following attribute to your methods.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;NS_RETURNS_NON_RETAINED&lt;/li&gt;
&lt;li&gt;NS_RETURNS_RETAINED&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So your method will now look like this.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; copyRightString NS_RETURNS_NON_RETAINED;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can also rename the method name to &lt;strong&gt;copyrightString&lt;/strong&gt; (note the case) or &lt;strong&gt;getCopyRightString&lt;/strong&gt; instead of adding an attribute. However, I wouldn&amp;#8217;t recommend the former method as it breaks the cocoa naming conventions (prefixing a method with &amp;#8220;get&amp;#8221; or &amp;#8220;set&amp;#8221; is Java-ish)&lt;/p&gt;
&lt;p&gt;You will see methods having the NS_RETURNS_* prefixes throughout the header files in Apple&amp;#8217;s own UIKit.framework or the foundation classes. Now that you know what happens behind the scenes and how compiler treats these decorations, you can solve crazy memory issues, like a crash when you call a &lt;strong&gt;copyRightString&lt;/strong&gt; in your method in a third party library.&lt;/p&gt;
&lt;p&gt;With that, let&amp;#8217;s get ready for climbing the next peak.&lt;/p&gt;
&lt;span id="Toll-free_bridging"&gt;&lt;h3&gt;Toll-free bridging&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;ARC &lt;strong&gt;doesn’t&lt;/strong&gt; manage Core Foundation objects. They say, there is no free lunch. ARC, takes it one step further. There is no free-casting between Core Foundation objects and equivalent Objective-C objects (NS* objects). Yes, that&amp;#8217;s right. You cannot cast a Core Foundation object to an equivalent Objective-C object (NS* object) without telling ARC how to manage ownerships.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s now see how to specify ownership transfers when you cast a Core Foundation object.&lt;br /&gt;
The following ownership transfer modifiers should be provided when you cast a Objective-C object to a Core Foundation object.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;__bridge&lt;/li&gt;
&lt;li&gt;__bridge_retained&lt;/li&gt;
&lt;li&gt;__bridge_transfer&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you migrate a project to ARC, you would have seen error messages like the one below.&lt;/p&gt;
&lt;div class="wp-caption aligncenter" style="width: 572px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Toll-free bridging.png" src="http://blog.mugunthkumar.com/wp-content/uploads/Toll-free-bridging.png" alt="Toll free bridging" width="562" height="196" border="0" /&gt;&lt;p class="wp-caption-text"&gt;ARC Error because of a missing bridge attribute in a Toll-free bridging code&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;You might also have proceeded by accepting the suggestions provided by the LLVM compiler. But now, let&amp;#8217;s dig deeper and understand the &amp;#8220;why&amp;#8221; behind it.&lt;/p&gt;
&lt;p&gt;The modifier, __bridge tells the ARC compiler that, it&amp;#8217;s a plain simple, bridging cast. That means, you ask the ARC compiler to do nothing extra when the transfer is made. You might think, if that is the case, Apple could have made this the default choice. But it was not made probably because, it&amp;#8217;s to preposterous to make such an assumption. Making such a bold assumption means, you would easily leak memory as there isn&amp;#8217;t a easier way to tell when you are actually releasing a Core Foundation object unlike a Objective-C object.&lt;/p&gt;
&lt;p&gt;The second modifier, __bridge_retained is used to tell the ARC compiler that the Objective-C object should be transferred to Core Foundation by bumping the retain count by 1 and it should be treated as if it is a newly created object (as opposed to a auto-released object). You use this modifier if the method was probably named like a creation method (starting with init, copy, mutableCopy etc.,) or if you are going to release the Objective-C object inside of Core Foundation using methods like CFRelease.&lt;/p&gt;
&lt;p&gt;The last modifier, __bridge_transfer is used to tell the ARC compiler that the Core Foundation object is to be transferred to ARC with a retain count of 1. This is used if you created a Core Foundation object using one of the CF***Create methods and want the ARC compiler to handle the memory management for you. That&amp;#8217;s you are transferring a Core Foundation object to ARC with a retain count of 1.&lt;/p&gt;
&lt;p&gt;As a side note on this, avoid using __bridge_retained and __bridge_transfer to trick the compiler to add retain and releases for you. Use it to improve your code readability and minimizing the number of manual memory management calls. (Move on if you don&amp;#8217;t understand this line. You will start understanding this automatically when you start using this in your own code)&lt;/p&gt;
&lt;span id="How_does_ARC_work_internally"&gt;&lt;h2&gt;How does ARC work internally?&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;ARC ain&amp;#8217;t magic, if you know how it works. But a little knowledge is a dangerous thing. Knowing how the ARC compiler works will help you more in understanding the error messages and compiler warnings spat out by it.&lt;/p&gt;
&lt;p&gt;The ARC compiler has two main parts, a front end compiler and an optimizer.&lt;/p&gt;
&lt;span id="ARC_front_end"&gt;&lt;h3&gt;ARC front end&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;The ARC front end compiler checks for every &amp;#8220;owned&amp;#8221; Objective-C object and inserts release appropriately. By owned object, I mean, an object whose ownership qualifier has been set. For example, if the &amp;#8220;owned&amp;#8221; object is a local variable, ARC front end compiler inserts a release at the end of the scope. This is because, by default all local variables are &amp;#8220;strong&amp;#8221; ly owned. If the object is a instance variable, the ARC front end compiler inserts a release statement in the dealloc method, if the ownership type is strong. For unsafe_unretained or weak ownership ARC doesn&amp;#8217;t do anything. It also takes care of calling the [super dealloc] for you and intact ARC compiler doesn&amp;#8217;t allow you to explicitly call dealloc.&lt;/p&gt;
&lt;p&gt;The ARC front end compiler also takes care of generating errors when it encounters a variable (local or instance) whose ownership qualifier is not set or when you explicitly calling dealloc.&lt;/p&gt;
&lt;span id="ARC_optimizer"&gt;&lt;h3&gt;ARC optimizer&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;The function of the ARC optimizer is to optimize the retain and release statements by removing them if they are inserted multiple times by the ARC front end compiler. It is this optimizer that ensures that performance is not affected by calling retain and release multiple times.&lt;/p&gt;
&lt;span id="The_actual_Migration_using_Xcode_4.2"&gt;&lt;h2&gt;The actual Migration using Xcode 4.2&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Xcode 4.2 has a wizard to automatically migrate your code for use with the ARC compiler. This means, the wizard rewrites some of your code, removes calls to retain/release and removes dealloc methods and calls to [super dealloc] for you.&lt;/p&gt;
&lt;p&gt;The first step is to open your project, select Edit -&amp;gt; Refactor -&amp;gt; Convert to Objective-C ARC from the menu.&lt;/p&gt;
&lt;div class="wp-caption alignnone" style="width: 610px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Refactor option.png" src="http://blog.mugunthkumar.com/wp-content/uploads/Refactor-option2.png" alt="Refactor option" width="600" height="417" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Migrating to Objective-C ARC using Xcode 4.2&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;When you select this option, you will be asked to select a target. If you have only one target, it&amp;#8217;s fine. If you have multiple targets in your application, you have to perform the ARC migration on every target. After you select a target, the wizard by default selects all source code files that belong to that project for ARC migration. If you are using third party libraries that are not yet ARC ready, you can uncheck those files in this step. This is illustrated in the screenshot below.&lt;/p&gt;
&lt;div class="wp-caption alignnone" style="width: 610px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Uncheck.png" src="http://blog.mugunthkumar.com/wp-content/uploads/Uncheck1.png" alt="Cannot convert" width="600" height="403" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Selecting your files for ARC exclusion&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;In the above project, since I know that ASIHttpRequest is not yet ARC compatible, I&amp;#8217;m selecting them and command-clicking them to show the option to uncheck all of them. When you do this, the wizard automatically adds a -fno-objc-arc compiler flag for all these files.&lt;/p&gt;
&lt;p&gt;The next step is to start the pre-checking process. The pre-checking process compiles the project and analyzes for potential problems before performing the actual migration. You might almost and always get a error message like this.&lt;/p&gt;
&lt;div class="wp-caption alignnone" style="width: 444px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Cannot convert.png" src="http://blog.mugunthkumar.com/wp-content/uploads/Cannot-convert1.png" alt="Cannot convert" width="434" height="148" border="0" /&gt;&lt;p class="wp-caption-text"&gt;The dreaded error message!&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Of course, 58 errors in this screenshot is actually quite low. You should expect anywhere in the range of 300+ for a mid sized project. But fret not, they aren&amp;#8217;t complicated at all to fix.&lt;/p&gt;
&lt;span id="Common_ARC_migration_errors"&gt;&lt;h2&gt;Common ARC migration errors&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;The number of errors that might prevent you from converting your project to ARC is usually high if your code is &amp;#8220;old&amp;#8221; or if it doesn&amp;#8217;t adhere to Objective-C design patterns. For example, accessing a iVar. While it&amp;#8217;s technically ok, you should almost and always use properties to access them outside of init and dealloc methods. If you have been using properties, ARC migration would be painless. If you were old skool, you have to feel the pain now. In this last section, I&amp;#8217;ll show you the most commonly occurring errors when you migrate your project.&lt;/p&gt;
&lt;span id="Cast_of_Objective-C_pointer_to_C_Pointer_type"&gt;&lt;h3&gt;Cast of Objective-C pointer to C Pointer type&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;This error is generated because ARC doesn&amp;#8217;t do toll-free bridging for you. As I explained before in the section, Toll-free bridging, requires the developer to explicitly specify ownership transfer qualifiers.&lt;br /&gt;
Use the various ownership transfer qualifiers I showed you before to fix this problem.&lt;/p&gt;
&lt;span id="performSelector_may_cause_a_leak_because_its_selector_is_unknown"&gt;&lt;h3&gt;performSelector may cause a leak because its selector is unknown&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;We now know that Objective-C ARC compiler knows more Objective-C than you. This error message is because of that. The ARC compiler tries to identify the method family and determine whether to add a retain or release to the returned value from the caller code. This means, if your method starts with init, alloc, copy, mutableCopy or new, the ARC compiler will add a release to the calling code after the variable scope ends. Since are using a selector to call a method dynamically at runtime, ARC doesn&amp;#8217;t really know if the method called returns a +1 retained object or a auto-released object. As such, ARC cannot reliably insert a retain or release to the returned object after its scope ends. This warning is shown to warn you of potential memory leaks.&lt;/p&gt;
&lt;p&gt;If you are sure that your code works fine without memory leaks, you can ignore this warning. To suppress this warning, you can turn off the compiler flag -Warc-performSelector-leaks warning on a line by line basis like this.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #6e371a;"&gt;#pragma clang diagnostic push&lt;/span&gt;
&lt;span style="color: #6e371a;"&gt;#pragma clang diagnostic ignored &amp;quot;-Warc-performSelector-leaks&amp;quot;&lt;/span&gt;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self performSelector&lt;span style="color: #002200;"&gt;:&lt;/span&gt;self.mySel&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
 &lt;span style="color: #6e371a;"&gt;#pragma clang diagnostic pop&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Unfortunately, you cannot annotate a dynamic selector using __attribute__ ((objc_method_family(*))).&lt;/p&gt;
&lt;span id="Receiver_type_82208221_doesn8217t_declare_the_method_with_selector_82208221"&gt;&lt;h3&gt;Receiver type &amp;#8220;*&amp;#8221; doesn&amp;#8217;t declare the method with selector &amp;#8220;*&amp;#8221;&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;ARC mandates that every method you call should be declared properly. With GCC, this was a warning. But LLVM makes this step mandatory since ARC needs to accurately identify and that is why you see an error like this.&lt;/p&gt;
&lt;div class="wp-caption alignnone" style="width: 610px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Undeclared Selectors.png" src="http://blog.mugunthkumar.com/wp-content/uploads/Undeclared-Selectors1.png" alt="Undeclared Selectors" width="600" height="28" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Error that you see when you don&amp;#39;t declare a receiver type&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;This error is also because of the fact that ARC needs to identify the method family to determine if it has to add a retain or release to the returned object. For example, in the above code, the method, returnMyGreatObject might return a NS_RETURNS_RETAINED. In this case, the ARC compiler has to insert a release after the returned object goes out of scope. The ARC compiler can know this only when you declare it formally. This is why, under ARC method declarations are mandatory. If you have been declaring methods formally under GCC, even when the compiler didn&amp;#8217;t enforce (so that the code was aesthetically beautiful) you wouldn&amp;#8217;t see this error at all. As I said before, the number of ARC migration errors is directly proportional to the quality of code you write. Fixing this error is fairly simple and all you have to do is to declare every method formally in the header file or on a private category extension.&lt;/p&gt;
&lt;span id="Common_workarounds_that_you_use_in_ARC_on_code_that_otherwise_looks_normal"&gt;&lt;h3&gt;Common workarounds that you use in ARC on code that otherwise looks normal&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;In some cases, while using ARC, you might end up writing code that looks as if it&amp;#8217;s written to &amp;#8220;please&amp;#8221; the ARC compiler rather than writing natural code. Unfortunately, nothing can be done to this and we all have to live with this. The next two sections explain when you might need to write unnecessary code like this to please the compiler.&lt;/p&gt;
&lt;span id="Capturing_82208221_strongly_is_likely_to_lead_to_a_retain_cycle"&gt;&lt;h4&gt;Capturing &amp;#8220;*&amp;#8221; strongly is likely to lead to a retain cycle&lt;/h4&gt;&lt;/span&gt;
&lt;div class="wp-caption alignnone" style="width: 610px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Capture.png" src="http://blog.mugunthkumar.com/wp-content/uploads/Capture1.png" alt="Capture" width="600" height="69" border="0" /&gt;&lt;p class="wp-caption-text"&gt;ARC and retain cycles&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;The last category of warning message is shown when a retain cycle is detected in your code. An example is shown below.&lt;/p&gt;
&lt;p&gt;This code was probably leaking the request object before ARC and increasing your memory footprint. But, thanks to ARC. You now know that code like these cause retain cycles that cannot be released automatically. Circumventing a retain cycle issue almost and always ends up breaking the cycle with a weak reference.&lt;/p&gt;
&lt;p&gt;Fixing this error is fairly simple and in this case, you can get a weak reference to the request object and copy it to the block. Within the block, convert it again to a strong reference. This is illustrated below.&lt;/p&gt;
&lt;div class="wp-caption alignnone" style="width: 580px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Capture fixed.png" src="http://blog.mugunthkumar.com/wp-content/uploads/Capture-fixed1.png" alt="Capture fixed" width="570" height="118" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Workaround for ARC and retain cycle issue&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;In the above code block, you can also replace references to __unsafe_unretained with __weak if you are deploying to a runtime that supports zero-ing weak references.&lt;/p&gt;
&lt;span id="Avoiding_retain_cycles_using___block"&gt;&lt;h4&gt;Avoiding retain cycles using __block&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;Sometimes, you need an object to live till as long as the completion handler on it can live. For example, a Block based UIAlertView can call a completion handler after the user presses a button on the UIAlertView.&lt;br /&gt;
For example,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;UIAlertView &lt;span style="color: #002200;"&gt;*&lt;/span&gt;alertView &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIAlertView alertViewWithTitle&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;Test&amp;quot;&lt;/span&gt; buttons&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSArray&lt;/span&gt; arrayWithObjects&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;Ok&amp;quot;&lt;/span&gt;, &lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;Cancel&amp;quot;&lt;/span&gt;, &lt;span style="color: #a61390;"&gt;nil&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; completionHandler&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;int&lt;/span&gt; tappedButtonIndex&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;  &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
	&lt;span style="color: #11740a; font-style: italic;"&gt;// do something based on the button tapped on alertView&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;alertView show&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the above case, the alertView gets deallocated by ARC as soon as it&amp;#8217;s shown and the call to completionHandler never gets executed (or even crashes).&lt;br /&gt;
To prevent this, you can use the __block decoration on UIAlertView declaration and copy it inside the block like&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;__block UIAlertView &lt;span style="color: #002200;"&gt;*&lt;/span&gt;alertView &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIAlertView alertViewWithTitle&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;Test&amp;quot;&lt;/span&gt; buttons&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSArray&lt;/span&gt; arrayWithObjects&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;Ok&amp;quot;&lt;/span&gt;, &lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;Cancel&amp;quot;&lt;/span&gt;, &lt;span style="color: #a61390;"&gt;nil&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; completionHandler&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;int&lt;/span&gt; tappedButtonIndex&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;  &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
	&lt;span style="color: #11740a; font-style: italic;"&gt;// do something based on the button tapped on alertView&lt;/span&gt;
	alertView &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #a61390;"&gt;nil&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;alertView show&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;ARC takes care of releasing it when you nil it inside the completionHandler. You will find this pattern used a lot when you work with completionHandlers in TwTweetComposeViewController or even UIViewController presentViewController:animated:completion: methods.&lt;/p&gt;
&lt;span id="That_last_question"&gt;&lt;h2&gt;That last question&lt;/h2&gt;&lt;/span&gt;
&lt;span id="When_should_you_migrate"&gt;&lt;h3&gt;When should you migrate?&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;&lt;strong&gt;NOW&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The performance benefits you get by using ARC is remarkable. Apple claims that the @autoreleasepool is over 6 times faster than NSAutoReleasePool objects used in your non-ARC code. This is because, @autoreleasepools don&amp;#8217;t allocate objects and all it does is must bump up the pointer retain counts. Similarly, NSObjects&amp;#8217; retain and release are optimized that you can expect a performance boost of anywhere around 2.5x. The third important performance benefit you will see is in methods that return autoreleased object. Under ARC, this variable is no longer transferred using the auto-release pool and what instead happens is a ownership transfer. Again this is upto 20x faster.&lt;/p&gt;
&lt;p&gt;Hence, don&amp;#8217;t wait till your dependent third party frameworks are migrated to ARC. You can always exclude them and go ahead and convert your code to ARC now.&lt;/p&gt;
&lt;span id="Where_to_go_from_here"&gt;&lt;h2&gt;Where to go from here?&lt;/h2&gt;&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;WWDC 2011 – Session 322 Introduction to Automatic Reference Counting&lt;/li&gt;
&lt;li&gt;WWDC 2011 – Session 322 Objective-C Advancements in depth&lt;/li&gt;
&lt;li&gt;Stop: You are warned. This link is only for hard code geeks. &lt;a href="http://clang.llvm.org/docs/AutomaticReferenceCounting.html"&gt;http://clang.llvm.org/docs/AutomaticReferenceCounting.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;WWDC 2011 – Session 308 &amp;#8211; Blocks and Grand Central Dispatch in Practice&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One last word, treat this post as a living document. I&amp;#8217;ll be updating the last few sections on new workarounds as and when I find a fix for them.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1412_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1412?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1412_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1412&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Farticles%2Fmigrating-your-code-to-objective-c-arc%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/mkstorekit-4-0-supporting-auto-renewable-subscriptions/' rel='bookmark' title='MKStoreKit 4.0 &amp;#8211; Supporting Auto Renewable Subscriptions'&gt;MKStoreKit 4.0 &amp;#8211; Supporting Auto Renewable Subscriptions&lt;/a&gt; &lt;small&gt;MKStoreKit started off in a pet project a couple of...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/c110sqUdDFgAILkCCbq1KTA-DpM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c110sqUdDFgAILkCCbq1KTA-DpM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/c110sqUdDFgAILkCCbq1KTA-DpM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c110sqUdDFgAILkCCbq1KTA-DpM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/zTyi6w_9bMk" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/articles/migrating-your-code-to-objective-c-arc/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">11</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/articles/migrating-your-code-to-objective-c-arc/</feedburner:origLink></entry><entry><title type="text">iOS Tutorial: Advanced Networking with MKNetworkKit</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/OViGhvLPkjM/" /><category term="Articles" /><category term="Coding" /><category term="Featured Articles" /><category term="ios" /><category term="mknetworkkit" /><category term="nsmutableurlrequest" /><category term="nsurlconnection" /><author><name>Mugunth Kumar</name></author><updated>2011-12-19T03:00:13-08:00</updated><id>http://blog.mugunthkumar.com/?p=1411</id><summary type="html">Couple of weeks ago, I wrote a clean, fast networking toolkit for iOS and Mac written for the LLVM Compiler 3.0 with ARC. Reception was very good that it was the &amp;#8220;most-watched&amp;#8221; repository on Github last week. Early adopters have sent me innumerable emails on how fast their network operations are, and how responsive their [...]
Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/ios-tutorial-image-cache-and-loading-thumbnails-using-mknetworkkit/' rel='bookmark' title='iOS Tutorial: Image Cache and Loading Thumbnails using MKNetworkKit'&gt;iOS Tutorial: Image Cache and Loading Thumbnails using MKNetworkKit&lt;/a&gt; &lt;small&gt;If you have been following me on Twitter or reading...&lt;/small&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/' rel='bookmark' title='iOS Framework: Introducing MKNetworkKit'&gt;iOS Framework: Introducing MKNetworkKit&lt;/a&gt; &lt;small&gt;How awesome would it be if a networking framework automatically...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;Couple of weeks ago, I wrote a &lt;a href="http://blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/"&gt;clean, fast networking toolkit for iOS and Mac&lt;/a&gt; written for the LLVM Compiler 3.0 with ARC.&lt;br /&gt;
Reception was very good that it was the &amp;#8220;most-watched&amp;#8221; repository on Github last week. Early adopters have sent me innumerable emails on how fast their network operations are, and how responsive their app is after integrating MKNetworkKit.&lt;/p&gt;
&lt;p&gt;&lt;div class='toc toc'&gt;
&lt;h2&gt;Contents&lt;/h2&gt;
&lt;ul class='toc-odd level-1'&gt;
	&lt;li&gt;
		&lt;a href="#Caching_your_responses_the_wrong_way"&gt;Caching your responses, the wrong way&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#Say_hello_to_MKNetworkKit"&gt;Say hello to MKNetworkKit&lt;/a&gt;
		&lt;ul class='toc-even level-2'&gt;
			&lt;li&gt;
				&lt;a href="#Behind_the_scenes"&gt;Behind the scenes&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
	&lt;li&gt;
		&lt;a href="#Freezing_Operations"&gt;Freezing Operations&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#Advanced_Tips"&gt;Advanced Tips&lt;/a&gt;
		&lt;ul class='toc-even level-2'&gt;
			&lt;li&gt;
				&lt;a href="#Friction-free_authentication"&gt;Friction-free authentication&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Custom_Authentication"&gt;Custom Authentication&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Overriding_MKNetworkEngine"&gt;Overriding MKNetworkEngine&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Overriding_MKNetworkOperation"&gt;Overriding MKNetworkOperation&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Image_Cache_with_MKNetworkEngine"&gt;Image Cache with MKNetworkEngine&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
	&lt;li&gt;
		&lt;a href="#Source_Code"&gt;Source Code&lt;/a&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class='toc-end'&gt;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;
MKNetworkKit is faster (and it makes your app feel smoother and faster with seamless transparent caching) in reality. There are two things that makes MKNetworkKit faster.&lt;br /&gt;
First, it&amp;#8217;s ARC based and the awesome LLVM 3.0 compiler brings in a ton of performance benefits. Using the @autoreleasepool block instead of NSAutoReleasePool in MKNetworkOperation alone should improve the performance by a huge factor (Apple claims it to be 6 times faster). If you still haven&amp;#8217;t migrated to ARC because you want to support those iOS 3.x users, read &lt;a href="http://mattgemmell.com/2011/12/05/latest-version/"&gt;this post&lt;/a&gt; by Matt Gemmell first.&lt;/p&gt;
&lt;p&gt;Second important performance benefit is seamless and transparent caching. By transparent caching, I mean, caching that involves zero overhead from the developer (That&amp;#8217;s you).&lt;/p&gt;
&lt;p&gt;Let me, in this post, brief you about how this seamless caching might help you. First, an example. You are refreshing a twitter stream. A GET request for that looks similar to&lt;/p&gt;
&lt;p&gt;GET http://twitter.com/mugunthkumar/statuses&lt;/p&gt;
&lt;span id="Caching_your_responses_the_wrong_way"&gt;&lt;h2&gt;Caching your responses, the wrong way&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Some developers cache responses using Core Data. &lt;strong&gt;STOP IT&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Using Core Data for caching is like using the military to kill bedbugs in your bedroom. DON&amp;#8217;T DO IT.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The problem when you implement Core Data is, you should program your view controllers to work with two kinds of data structures. One, JSON/XML from server and the other, Core Data NSManagedObjects. Some &amp;#8220;clever&amp;#8221; developers &amp;#8220;take it to the next level&amp;#8221; by just programming their view controllers to work with only Core Data. The design goes like this. The network layer talks to the server and updates Core Data Store. Once the store is updated, send a NSNotification to &amp;#8220;refresh&amp;#8221; view controllers.&lt;br /&gt;
This may sound clever to many. But it&amp;#8217;s completely WRONG. I REPEAT. COMPLETELY WRONG. Core Data (or even structured SQL storage) is not meant for that. Core Data is a structured storage for persisting/serializing Object graphs in your application. Don&amp;#8217;t use it for storing objects that have a low life time. Thumbnail images, list of tweets etc., just don&amp;#8217;t belong there. Secondly, this would require you to read and write to flash memory on the iDevice which have a limited read/write cycle. Finally, reading and writing to disk (in this case, Core Data) is a very ugly way to transfer data from one class to another (in this case, from your Network Layer to View Controllers)&lt;/p&gt;
&lt;span id="Say_hello_to_MKNetworkKit"&gt;&lt;h2&gt;Say hello to MKNetworkKit&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkKit calls the SAME completion handler with cached data if you are making the call for the second time. When the network connectivity is proper, MKNetworkKit calls your completion handler twice. First with the cached data and again after fetching the latest data from server. As such, you can design your view controllers to work with just ONE kind of data, data from server. If you have an app that doesn&amp;#8217;t cache and doesn&amp;#8217;t work offline, just replace your networking library with MKNetworkKit and you get caching for free. Not even a single line of code change is required on your view controllers. Caching is transparent. Your view controllers needs to work with the same data structure, no matter whether the data is from cache or server.&lt;/p&gt;
&lt;span id="Behind_the_scenes"&gt;&lt;h3&gt;Behind the scenes&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkKit caching is super light-weight and it caches your responses in a NSMutableDictionary. Doesn&amp;#8217;t that lead to high memory usage? Yes. of-course, but MKNetworkKit is clever. It observes the UIApplicationDidReceiveMemoryWarningNotification and flushes the dictionary to disk. The next time you make a request to the cached URL, the cached data is brought back to memory. So in-effect, it has a in-memory cache and disk cache and uses a least recently used algorithm to flush items to disk. The MKNetworkEngine class has methods that can be over-ridden to control the cache cost.&lt;/p&gt;
&lt;p&gt;Just override the method&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;int&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; cacheMemoryCost;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and return a higher/lower value based on your application&amp;#8217;s requirements.&lt;/p&gt;
&lt;p&gt;MKNetworkKit caching works like a intermediate proxy server by intercepting the response headers. So, when a second GET request to the same URL is made, MKNetworkKit behaves the following way.&lt;/p&gt;
&lt;p&gt;1) For GET requests that sent a ETag in the header previously (for example, requests to Amazon S3 servers), MKNetworkKit sends a second request as a HEAD request (even if you specify as GET) with IF-NONE-MATCHheader. Most servers that send ETag (like Amazon S3) responds to IF-NONE-MATCH by sending the real data only when it has been changed. Otherwise, they return a 304 Not Modified which MKNetworkKit safely ignores. So data transfer is really not huge. Even this request is honored only after 1 day. So, repeated requests to the same thumbnail image doesn&amp;#8217;t even hit the server.&lt;/p&gt;
&lt;p&gt;2) For any GET request that contained a Cache-Control:max-age=in the header, MKNetworkKit honors that and makes the second request only after the expiry date. For dynamically generated requests, you should set Cache-Control on server. This not only helps MKNetworkKit, but most proxy servers along the way.&lt;/p&gt;
&lt;p&gt;3) For requests that contained a Last-Modified field in the header, MKNetworkKit sends a &amp;#8220;IF-MODIFIED-SINCE&amp;#8221; HEAD request. This again works like the IF-NONE-MATCH. The server, either sends the complete data or a 304 Not Modified.&lt;/p&gt;
&lt;p&gt;4) For servers that implement Cache-Control: no-cache, MKNetworkKit goes one step ahead and makes a second request only after a minute (60 sec). So repeated refreshes to often refreshed page will not exactly hit the server. For example, refreshing foursquare check-ins. It&amp;#8217;s rare for these information to change within the next 60 sec.&lt;/p&gt;
&lt;p&gt;5) For performance reasons, when the response type is an image, and the response headers doesn&amp;#8217;t have any cache control information, MKNetworkKit assumes an expiry date of 7 days.&lt;/p&gt;
&lt;p&gt;The last two are not an RFC standard. But these optimizations make network operations fast on a mobile devices even if the server isn&amp;#8217;t implemented in an optimized way. All POST, PUT, HEAD and DELETE requests are ignored and not cached.&lt;/p&gt;
&lt;p&gt;And, of course, you can customize all these behaviors by editing the values in MKNetworkKit.h&lt;/p&gt;
&lt;span id="Freezing_Operations"&gt;&lt;h2&gt;Freezing Operations&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Another very important feature of MKNetworkKit is operation freezing. Imagine that, your customer take an awesome photo with your own &amp;#8220;Instagram-killer&amp;#8221; app, but since he is at a remote exotic place, 3G connectivity is poor and uploading the photo fails. Without MKNetworkKit, you should remember the photo related meta data, store the photo&amp;#8217;s NSData in a file and upload the operation the next time the app is launched. Painful!&lt;br /&gt;
With MKNetworkKit, you mark the photo upload operation is &amp;#8220;freezable&amp;#8221;. This means, in the event of network failure, your operations are automatically serialized (frozen beneath snow) and restored the next time the app launches, all for free.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;MKNetworkOperation &lt;span style="color: #002200;"&gt;*&lt;/span&gt;op &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;myEngine operationWithPath&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;/imageUpload&amp;quot;&lt;/span&gt; params&lt;span style="color: #002200;"&gt;:&lt;/span&gt;paramsDict httpMethod&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;op setFreezable&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #a61390;"&gt;YES&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;; &lt;span style="color: #11740a; font-style: italic;"&gt;// ONE EXTRA LINE&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;myEngine enqueOperation&lt;span style="color: #002200;"&gt;:&lt;/span&gt;op&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can mark any POST/PUT/DELETE operation as freezable. GET operations are not freezable and MKNetworkKit ignores your call to setFreezable: if your operation is a &amp;#8220;GET&amp;#8221; operation.&lt;/p&gt;
&lt;span id="Advanced_Tips"&gt;&lt;h2&gt;Advanced Tips&lt;/h2&gt;&lt;/span&gt;
&lt;span id="Friction-free_authentication"&gt;&lt;h3&gt;Friction-free authentication&lt;/h3&gt;&lt;/span&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;MKNetworkOperation &lt;span style="color: #002200;"&gt;*&lt;/span&gt;op &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;myEngine operationWithPath&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;/letmein&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;op setUserName&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;mugunth&amp;quot;&lt;/span&gt; password&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;mYsEkReTpAsSwOrD&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;; &lt;span style="color: #11740a; font-style: italic;"&gt;// ONE EXTRA LINE&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;op setUserName&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;mugunth&amp;quot;&lt;/span&gt; password&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;mYsEkReTpAsSwOrD&amp;quot;&lt;/span&gt; basicAuth&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #a61390;"&gt;YES&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;; &lt;span style="color: #11740a; font-style: italic;"&gt;// OR THIS LINE&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;myEngine enqueOperation&lt;span style="color: #002200;"&gt;:&lt;/span&gt;op&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When your server uses HTTP Basic auth or Digest auth or even Windows NTLM authentication, all you need to do is to set your username and password and MKNetworkKit auto-magically authenticates your request!. For NTLM authentication, just ensure your username is &amp;#8220;domain\username&amp;#8221;. There is no separate method setDomain: or something.&lt;/p&gt;
&lt;p&gt;You can also set basicAuth:YES to send the credentials even before receiving the authentication challenge. However, this works only if your server uses HTTP Basic Authentication.&lt;/p&gt;
&lt;span id="Custom_Authentication"&gt;&lt;h3&gt;Custom Authentication&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;If your server uses HTML Form authentication, you can override the authHandler block and provide custom auth mechanisms.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;MKNetworkOperation &lt;span style="color: #002200;"&gt;*&lt;/span&gt;op &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;myEngine operationWithPath&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;/letmein&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
op.authHandler &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSURLAuthenticationChallenge&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;cred&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt; 
&lt;span style="color: #11740a; font-style: italic;"&gt;// show a web view controller or do whatever you want and finally, when you have a credentials ready, just call &lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;challenge.sender useCredential&lt;span style="color: #002200;"&gt;:&lt;/span&gt;credential forAuthenticationChallenge&lt;span style="color: #002200;"&gt;:&lt;/span&gt;challenge&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;myEngine enqueOperation&lt;span style="color: #002200;"&gt;:&lt;/span&gt;op&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;span id="Overriding_MKNetworkEngine"&gt;&lt;h3&gt;Overriding MKNetworkEngine&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Tweaking the URL building methods with MKNetworkEngine is easy. Let me start by giving you an example. Imagine that you have a server which authenticates a logged in user and after authentication, it expects a Authorization header to be set with an access token.&lt;br /&gt;
You need to have a &lt;a href="http://en.wikipedia.org/wiki/Factory_method_pattern"&gt;factory method&lt;/a&gt; that creates URLs customized to your web service. This could include adding a authorization header in our case. You can do this by overriding the method,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; enqueueOperation&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;MKNetworkOperation&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; operation;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For example, in the above case, you can check your engine subclass for an access token and add it to the operation&amp;#8217;s header in this method (if you have one).&lt;/p&gt;
&lt;span id="Overriding_MKNetworkOperation"&gt;&lt;h3&gt;Overriding MKNetworkOperation&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Sometimes, you might do custom error handling based on the response from your server. For example, your server might send a valid HTTP response (status code 200) which could be an internal error, like &amp;#8220;Invalid User&amp;#8221;. Business logic errors are better handled with your own application level error codes. You overriding MKNetworkOperation to customize the success/failure reporting. I would highly recommend doing this along with designing your server to send error codes for error conditions.&lt;/p&gt;
&lt;p&gt;The following methods are to be overridden for customizing error handling.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; operationSucceeded;
&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; operationFailedWithError&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSError&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; error;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For example, in the previous case, you can override operationSucceeded, inspect the response and if the response was indeed a business logic error (&amp;#8220;Invalid User&amp;#8221;), you can call the [super operationFailedWithError:[Your custom error class for "Invalid User"]];&lt;br /&gt;
Otherwise, call [super operationSucceeded].&lt;/p&gt;
&lt;p&gt;You can also override operationFailedWithError to introspect the actual cause of the error, if your server sends any error related information in the dictionary.&lt;/p&gt;
&lt;p&gt;The reason for overriding at this level is to minimize error handling at view controller layer. So your presentation layer, UIViewController subclasses will be cleaner to read.&lt;/p&gt;
&lt;p&gt;If you have subclassed the MKNetworkOperation and want the factory method in your engine subclass, operationWithURLString:params:httpMethod to prepare an operation of your subclass. To register your operation subclass with the engine, you can call the registerOperationSubclass: method.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; registerOperationSubclass&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;Class&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; aClass;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Your code fragment might look like,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.myEngine registerOperationSubclass&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;MyAppNetworkOperation class&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;span id="Image_Cache_with_MKNetworkEngine"&gt;&lt;h3&gt;Image Cache with MKNetworkEngine&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkEngine has a handy method to load images from a server. It&amp;#8217;s built-in cache mechanism ensures, your images are cached without using any third-party image cache libraries. That means your code base is even leaner.&lt;br /&gt;
You can use the following method of MKNetworkEngine to load images.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; imageAtURL&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;url onCompletion&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;MKNKImageBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; imageFetchedBlock;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;MKNKImageBlock is defined like this.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #a61390;"&gt;typedef&lt;/span&gt; &lt;span style="color: #a61390;"&gt;void&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;MKNKImageBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIImage&lt;span style="color: #002200;"&gt;*&lt;/span&gt; fetchedImage, &lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt; url, &lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt; isInCache&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So your calling code will look like,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;ApplicationDelegate.myAppEngine imageAtURL&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt; URLWithString&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;http://example.com/image.png&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; onCompletion&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIImage &lt;span style="color: #002200;"&gt;*&lt;/span&gt;fetchedImage, &lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;fetchedURL, &lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt; isInCache&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
        self.imageView.image &lt;span style="color: #002200;"&gt;=&lt;/span&gt; fetchedImage;
    &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you are loading images onto a imageView inside a tableview cell, you can check if the completed URL is same as the passed URL&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;ApplicationDelegate.myAppEngine imageAtURL&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt; URLWithString&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;http://example.com/image.png&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; onCompletion&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;UIImage &lt;span style="color: #002200;"&gt;*&lt;/span&gt;fetchedImage, &lt;span style="color: #400080;"&gt;NSURL&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;fetchedURL, &lt;span style="color: #a61390;"&gt;BOOL&lt;/span&gt; isInCache&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
	&lt;span style="color: #a61390;"&gt;if&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;originalURL &lt;span style="color: #002200;"&gt;==&lt;/span&gt; fetchedURL&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;
        cell.imageView.image &lt;span style="color: #002200;"&gt;=&lt;/span&gt; fetchedImage;
    &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This check is necessary as tableview cells might be recycled and a cell might end up getting images from multiple network operations.&lt;/p&gt;
&lt;p&gt;You might also want to read my other elaborate post on &lt;a href="http://blog.mugunthkumar.com/coding/ios-tutorial-image-cache-and-loading-thumbnails-using-mknetworkkit/"&gt;Image Caching with MKNetworkKit&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Lastly, if you are fading in your images like those fancy apps, add your fade-in logic if the image is loaded from server and not from cache.&lt;/p&gt;
&lt;span id="Source_Code"&gt;&lt;h2&gt;Source Code&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;&lt;a href="https://github.com/MugunthKumar/MKNetworkKit"&gt;MKNetworkKit&lt;/a&gt; on Github&lt;/p&gt;
&lt;p&gt;MKNetworkKit might look simple, but it&amp;#8217;s incredibly powerful. Use it in your apps and tell me how it scores. My next blog post would be on how to write a better RESTful server that serves a mobile device. Watch this space, subscribe to &lt;a href="http://feeds.feedburner.com/MugunthKumar"&gt;my feed&lt;/a&gt; or &lt;a href="http://twitter.com/MugunthKumar"&gt;follow me on twitter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Interested in learning in-depth features of Objective-C and iOS? You should get my book.&lt;/p&gt;
&lt;p&gt;Amazon - &lt;a href="http://mk.sg/ios5book"&gt;http://mk.sg/ios5book&lt;br /&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;iBooks - &lt;a href="http://mk.sg/ibook"&gt;http://mk.sg/ibook&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Wiley &amp;#8211; &lt;a href="http://mk.sg/book"&gt;http://mk.sg/book&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Book Depository &amp;#8211; &lt;a href="http://mk.sg/bdbook"&gt;http://mk.sg/bdbook&lt;/a&gt;&lt;br /&gt;
&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1411_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1411?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1411_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1411&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fios-tutorial-advanced-networking-with-mknetworkkit%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/ios-tutorial-image-cache-and-loading-thumbnails-using-mknetworkkit/' rel='bookmark' title='iOS Tutorial: Image Cache and Loading Thumbnails using MKNetworkKit'&gt;iOS Tutorial: Image Cache and Loading Thumbnails using MKNetworkKit&lt;/a&gt; &lt;small&gt;If you have been following me on Twitter or reading...&lt;/small&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/' rel='bookmark' title='iOS Framework: Introducing MKNetworkKit'&gt;iOS Framework: Introducing MKNetworkKit&lt;/a&gt; &lt;small&gt;How awesome would it be if a networking framework automatically...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Fd_U1-raUqZ478AqOg8iidvDmjk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Fd_U1-raUqZ478AqOg8iidvDmjk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Fd_U1-raUqZ478AqOg8iidvDmjk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Fd_U1-raUqZ478AqOg8iidvDmjk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/OViGhvLPkjM" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/coding/ios-tutorial-advanced-networking-with-mknetworkkit/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">13</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/coding/ios-tutorial-advanced-networking-with-mknetworkkit/</feedburner:origLink></entry><entry><title type="text">iOS Framework: Introducing MKNetworkKit</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/G7RW0HzQu5Q/" /><category term="Featured Articles" /><category term="Products" /><category term="arc" /><category term="blocks" /><category term="ios5" /><category term="mknetworkkit" /><category term="networking" /><category term="restful" /><author><name>Mugunth Kumar</name></author><updated>2011-11-29T03:22:49-08:00</updated><id>http://blog.mugunthkumar.com/?p=1319</id><summary type="html">How awesome would it be if a networking framework automatically takes care of caching responses for you? How awesome would it be if a networking framework automatically remembers your operations when your client is offline? You favorite a tweet or mark a feed as read when you are offline and the Networking Framework performs all [...]
Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/ios-tutorial-advanced-networking-with-mknetworkkit/' rel='bookmark' title='iOS Tutorial: Advanced Networking with MKNetworkKit'&gt;iOS Tutorial: Advanced Networking with MKNetworkKit&lt;/a&gt; &lt;small&gt;Couple of weeks ago, I wrote a clean, fast networking...&lt;/small&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/products/introducing-my-book-ios-5-programming-pushing-the-limits/' rel='bookmark' title='Introducing my book: iOS 5 Programming Pushing the Limits'&gt;Introducing my book: iOS 5 Programming Pushing the Limits&lt;/a&gt; &lt;small&gt;iOS 5 Programming Pushing the Limits Developing Extraordinary Mobile Apps...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;How awesome would it be if a networking framework automatically takes care of caching responses for you?&lt;/p&gt;
&lt;p&gt;How awesome would it be if a networking framework automatically remembers your operations when your client is offline?&lt;/p&gt;
&lt;p&gt;You favorite a tweet or mark a feed as read when you are offline and the Networking Framework performs all these operations when the device comes back online, all with no extra coding effort from you. Introducing MKNetworkKit.&lt;/p&gt;
&lt;div class='toc toc'&gt;
&lt;h2&gt;Contents&lt;/h2&gt;
&lt;ul class='toc-odd level-1'&gt;
	&lt;li&gt;
		&lt;a href="#What_is_MKNetworkKit"&gt;What is MKNetworkKit?&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#Features"&gt;Features&lt;/a&gt;
		&lt;ul class='toc-even level-2'&gt;
&lt;ul class='toc-odd level-3'&gt;
			&lt;li&gt;
				&lt;a href="#Super_light-weight"&gt;Super light-weight&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Single_Shared_Queue_for_your_entire_application."&gt;Single Shared Queue for your entire application.&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Showing_the_Network_Activity_Indicator_correctly"&gt;Showing the Network Activity Indicator correctly&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Auto_queue_sizing"&gt;Auto queue sizing&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Auto_caching"&gt;Auto caching&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Operation_freezing"&gt;Operation freezing&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Performs_exactly_one_operation_for_similar_requests"&gt;Performs exactly one operation for similar requests&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Image_Caching"&gt;Image Caching&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Performance"&gt;Performance&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Full_support_for_Objective-C_ARC"&gt;Full support for Objective-C ARC&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
&lt;/ul&gt;
	&lt;li&gt;
		&lt;a href="#How_to_use"&gt;How to use&lt;/a&gt;
		&lt;ul class='toc-even level-2'&gt;
			&lt;li&gt;
				&lt;a href="#Adding_the_MKNetworkKit"&gt;Adding the MKNetworkKit&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Classes_in_MKNetworkKit"&gt;Classes in MKNetworkKit&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Example_1:"&gt;Example 1:&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Example_2:"&gt;Example 2:&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Example_3:"&gt;Example 3:&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Example_4:"&gt;Example 4:&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Caching_operations"&gt;Caching operations&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Freezing_operations"&gt;Freezing operations&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Convenience_methods_in_MKNetworkOperation"&gt;Convenience methods in MKNetworkOperation&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#Convenience_macros"&gt;Convenience macros&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href="#A_note_on_GCD"&gt;A note on GCD&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
	&lt;li&gt;
		&lt;a href="#Documentation"&gt;Documentation&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#Source_Code"&gt;Source Code&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#Feature_requests"&gt;Feature requests&lt;/a&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#Licensing"&gt;Licensing&lt;/a&gt;
	&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class='toc-end'&gt;&amp;nbsp;&lt;/div&gt;
&lt;span id="What_is_MKNetworkKit"&gt;&lt;h2&gt;What is MKNetworkKit?&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;&lt;strong&gt;MKNetworkKit&lt;/strong&gt; is a networking framework written in Objective-C that is seamless, block based, ARC ready and easy to use.&lt;br /&gt;
MKNetworkKit is inspired by the other two popular networking frameworks, ASIHTTPRequest and AFNetworking. Marrying the feature set from both, MKNetworkKit throws in a bunch of new features. In addition to this, MKNetworkKit mandates you to write slightly more code than the other frameworks at the expense of code clarity. With MKNetworkKit, it&amp;#8217;s hard to write ugly networking code.&lt;/p&gt;
&lt;span id="Features"&gt;&lt;h2&gt;Features&lt;/h2&gt;&lt;/span&gt;
&lt;span id="Super_light-weight"&gt;&lt;h4&gt;Super light-weight&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;The complete kit is just 2 major classes and some category methods. This means, adopting MKNetworkKit should be super easy.&lt;/p&gt;
&lt;span id="Single_Shared_Queue_for_your_entire_application."&gt;&lt;h4&gt;Single Shared Queue for your entire application.&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;Apps that depend heavily on Internet connectivity should optimize the number of concurrent network operations. Unfortunately, there is no networking framework that does this correctly. Let me give you an example of what can go wrong if you don&amp;#8217;t optimize/control the number of concurrent network operations in your app.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s assume that you are uploading a bunch of photos (think &lt;a href="http://www.color.com/"&gt;Color&lt;/a&gt; or &lt;a href="http://batch.com/"&gt;Batch&lt;/a&gt;) to your server. Most mobile networks (3G) don&amp;#8217;t allow more than two concurrent HTTP connections from a given IP address. That is, from your device, you cannot open more than two concurrent HTTP connections on a 3G network. Edge is even worse. You can&amp;#8217;t, in most cases, open more than one connection. This limit is considerably high (six) on a traditional home broadband (Wifi). However, since your iDevice is not always connected to Wifi, you should be prepared for throttled/restricted network connectivity. On any normal case, the iDevice is mostly connected to a 3G network, which means, you are restricted to upload only two photos in parallel. Now, it is not the slow upload speed that hurts. The real problem arises when you open a view that loads thumbnails of photos (say on a different view) while this uploading operations are running in the background. When you don&amp;#8217;t properly control the queue size across the app, your thumbnail loading operations will just timeout which is not really the right way to do it. The right way to do this is to prioritize your thumbnail loading operation or wait till the upload is complete and the load thumbnails. This requires you to have a single queue across the entire app. MKNetworkKit ensures this automatically by using a single shared queue for every instance of it. While MKNetworkKit is not a singleton by itself, the shared queue is.&lt;/p&gt;
&lt;span id="Showing_the_Network_Activity_Indicator_correctly"&gt;&lt;h4&gt;Showing the Network Activity Indicator correctly&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;While there are many third party classes that uses &amp;#8220;incrementing&amp;#8221; and &amp;#8220;decrementing&amp;#8221; the number of network calls and using that to show the network activity indicator, MKNetworkKit backs on the single shared queue principle and shows the activity indicator automatically when there is an operation running in the shared queue by observing (KVO) the operationCount property. As a developer, you normally don&amp;#8217;t have to worry about setting the network activity indicator manually, ever again.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;    &lt;span style="color: #a61390;"&gt;if&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;object &lt;span style="color: #002200;"&gt;==&lt;/span&gt; _sharedNetworkQueue &lt;span style="color: #002200;"&gt;&amp;amp;&lt;/span&gt;amp;&lt;span style="color: #002200;"&gt;&amp;amp;&lt;/span&gt;amp; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;keyPath isEqualToString&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;operationCount&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;UIApplication sharedApplication&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;.networkActivityIndicatorVisible &lt;span style="color: #002200;"&gt;=&lt;/span&gt;
        &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;_sharedNetworkQueue.operations count&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;amp;&lt;/span&gt;gt; &lt;span style="color: #2400d9;"&gt;0&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;span id="Auto_queue_sizing"&gt;&lt;h4&gt;Auto queue sizing&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;Continuing the previous discussion, I told that most mobile networks don&amp;#8217;t allow more than two concurrent connections. So your queue size should be set to two, when the current network connectivity is 3G. MKNetworkKit automatically handles this for you. When the network drops to 3G/EDGE/GPRS, it changes the number of concurrent operations that can be performed to 2. This is automatically changed back to 6 when the device connects back to a Wifi network. With this technique in place, you will see a huge performance benefit when you are loading thumbnails (or multiple similar small requests) for a photo library from a remote server over 3G.&lt;/p&gt;
&lt;span id="Auto_caching"&gt;&lt;h4&gt;Auto caching&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkKit can automatically cache all your &amp;#8220;GET&amp;#8221; requests. When you make the same request again, MKNetworkKit calls your completion handler with the cached version of the response (if it&amp;#8217;s available) almost immediately. It also makes a call to the remote server again. After the server data is fetched, your completion handler is called again with the new response data. This means, you don&amp;#8217;t have to handle caching manually on your side. All you need to do is call one method,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;MKNetworkEngine sharedEngine&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; useCache&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Optionally, you can override methods in your MKNetworkEngine subclass to customize your cache directory and in-memory cache cost.&lt;/p&gt;
&lt;span id="Operation_freezing"&gt;&lt;h4&gt;Operation freezing&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;With MKNetworkKit, you have the ability to freeze your network operations. When you freeze an operation, in case of network connectivity losses, they will be serialized automatically and performed once the device comes back online. Think of &amp;#8220;drafts&amp;#8221; in your twitter client.&lt;/p&gt;
&lt;p&gt;When you post a tweet, mark that network call as freezable and MKNetworkKit automatically takes care of freezing and restoring these requests for you! So the tweets get sent later without you writing a single line of additional code. You can use this for other operations like favoring a tweet or sharing a post from your Google reader client, adding a link to Instapaper and similar operations.&lt;/p&gt;
&lt;span id="Performs_exactly_one_operation_for_similar_requests"&gt;&lt;h4&gt;Performs exactly one operation for similar requests&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;When you load thumbnails (for a twitter stream), you might end up creating a new request for every avatar image. But in reality, you only need as many requests as there are unique URLs. With MKNetworkKit, every GET request you queue gets executed exactly once. MKNetworkKit is intelligent enough not to cache &amp;#8220;POST&amp;#8221; http requests.&lt;/p&gt;
&lt;span id="Image_Caching"&gt;&lt;h4&gt;Image Caching&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkKit can be seamlessly used for caching thumbnail images. By overriding a few methods, you can set how many images should be held in the in-memory cache and where in the Caches directory it should be saved. Overriding these methods are completely optional.&lt;/p&gt;
&lt;span id="Performance"&gt;&lt;h4&gt;Performance&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;One word. SPEED. MKNetworkKit caching is seamless. It works like NSCache, except that, when there is a memory warning, the in-memory cache is written to the Caches directory.&lt;/p&gt;
&lt;span id="Full_support_for_Objective-C_ARC"&gt;&lt;h4&gt;Full support for Objective-C ARC&lt;/h4&gt;&lt;/span&gt;
&lt;p&gt;You normally choose a new networking framework for new projects. MKNetworkKit is not meant for replacing your existing framework (though you can, it&amp;#8217;s quite a tedious job). On new projects, you will almost and always want to enable ARC and as on date of writing this, MKNetworkKit is probably the only networking framework that is fully ARC ready. ARC based memory management is usually an order of magnitude faster than non-ARC based memory management code.&lt;/p&gt;
&lt;span id="How_to_use"&gt;&lt;h2&gt;How to use&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Ok, Enough self-praises. Let us now see how to use the framework.&lt;/p&gt;
&lt;span id="Adding_the_MKNetworkKit"&gt;&lt;h3&gt;Adding the MKNetworkKit&lt;/h3&gt;&lt;/span&gt;
&lt;ol&gt;
&lt;li&gt;Drag the MKNetworkKit directory to your project.&lt;/li&gt;
&lt;li&gt;Add the CFNetwork.Framework, SystemConfiguration.framework and Security.framework.&lt;/li&gt;
&lt;li&gt;Include MKNetworkKit.h to your PCH file&lt;/li&gt;
&lt;li&gt;Delete NSAlert+MKNetworkKitAdditions.h file if you are building for iOS.&lt;/li&gt;
&lt;li&gt;Delete UIAlertView+MKNetworkKitAdditions.h file if you are building for Mac.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You are done. Just 5 core files and there you go. A powerful networking kit.&lt;/p&gt;
&lt;span id="Classes_in_MKNetworkKit"&gt;&lt;h3&gt;Classes in MKNetworkKit&lt;/h3&gt;&lt;/span&gt;
&lt;ol&gt;
&lt;li&gt;MKNetworkOperation&lt;/li&gt;
&lt;li&gt;MKNetworkEngine&lt;/li&gt;
&lt;li&gt;Miscellaneous helper classes (Apple&amp;#8217;s Reachability) and categories&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I believe in simplicity. Apple has done the heavy lifting of writing the actual networking code. What a third-party networking framework should provide is an elegant queue based networking with optional caching. I believe that, any third party framework should have under 10 classes (whether it&amp;#8217;s networking or UIKit replacement or whatever). More than that is a bloat. Three 20 library is an example of bloat and so is ShareKit. May be it&amp;#8217;s good. But it still huge and bloated. ASIHttpRequest or AFNetworking are lean and lightweight, unlike RESTKit. JSONKit is lightweight unlike TouchJSON (or any of the TouchCode libraries). May be it&amp;#8217;s just me, but I just can&amp;#8217;t take it when more than a third of source code lines in my app comes from a third party library.&lt;/p&gt;
&lt;p&gt;The problem with a huge framework is the difficulty in understanding the internal working and the ability to customize it to suit your needs (in case you need to). My frameworks (MKStoreKit for adding In App Purchases to your app) have always been super easy to use and I believe MKNetworkKit would also be the same. For using MKNetworkKit, all you need to know are the methods exposed by the two classes MKNetworkOperation and MKNetworkEngine. MKNetworkOperation is similar to the ASIHttpRequest class. It is a subclass of NSOperation and it wraps your request and response classes. You create a MKNetworkOperation for every network operation you need in your application.&lt;/p&gt;
&lt;p&gt;MKNetworkEngine is a pseudo-singleton class that manages the network queue in your application. It&amp;#8217;s a pseudo-singleton, in the sense, for simple requests, you should use MKNetworkEngine methods directly. For more powerful customization, you should subclass it. Every MKNetworkEngine subclass has its own Reachability object that notifies it of server reachability notifications. You should consider creating a subclass of MKNetworkEngine for every unique REST server you use. It&amp;#8217;s pseudo-singleton in the sense, every single request in any of it&amp;#8217;s subclass goes through one and only one single queue.&lt;/p&gt;
&lt;p&gt;You can retain instances of your MKNetworkEngine in your application delegate just like CoreData managedObjectContext class. When you use MKNetworkKit, you create an MKNetworkEngine sub class to logically group your network calls. That is, all Yahoo related methods go under one single class and all Facebook related methods into another class. We will now look at three different examples of using this framework.&lt;/p&gt;
&lt;span id="Example_1:"&gt;&lt;h3&gt;Example 1:&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Let&amp;#8217;s now create a &amp;#8220;YahooEngine&amp;#8221; that pulls currency exchange rates from Yahoo finance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create a YahooEngine class as a subclass of MKNetworkEngine. MKNetworkEngine init method takes hostname and custom headers (if any). The custom headers is optional and can be nil. If you are writing your own REST server (unlike this case), you might consider adding client app version and other misc data like client identifier.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;    &lt;span style="color: #400080;"&gt;NSMutableDictionary&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;headerFields &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSMutableDictionary&lt;/span&gt; dictionary&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;headerFields setValue&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;iOS&amp;quot;&lt;/span&gt; forKey&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;x-client-identifier&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
    self.engine &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;YahooEngine alloc&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt; initWithHostName&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;download.finance.yahoo.com&amp;quot;&lt;/span&gt;
                       customHeaderFields&lt;span style="color: #002200;"&gt;:&lt;/span&gt;headerFields&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that, while yahoo doesn&amp;#8217;t mandate you to send x-client-identifier in the header, the sample code shown above sends this just to illustrate this feature.&lt;/p&gt;
&lt;p&gt;Since the complete code is ARC, it&amp;#8217;s up to you as a developer to own (strong reference) the Engine instance.&lt;/p&gt;
&lt;p&gt;When you create a MKNetworkEngine subclass, Reachability implementation is done automatically for you. That&amp;#8217;s when your server goes down or due to some unforeseen circumstances, the hostname is not reachable, your requests will automatically be queued/frozen. For more information about freezing your operations, read the section Freezing Operations later in the page.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Designing the Engine class (Separation of concerns)&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s now start write the methods in Yahoo Engine to fetch exchange rates. The engine methods will be called from your view controller. A good design practice is to ensure that your engine class doesn&amp;#8217;t expose URL/HTTPHeaders to the calling class. Your view should not &amp;#8220;know&amp;#8221; about URL endpoints or the parameters needed. This means, parameters to methods in your Yahoo Engine should be the currencies and the number of currency units. The return value of this method could be a double value that is the exchange rate factor and may be the timestamp of the time it was fetched. Since operations are not performed synchronously, you should return these values on blocks. An example of this would be,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;MKNetworkOperation&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; currencyRateFor&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; sourceCurrency
                   	    inCurrency&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSString&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; targetCurrency
			  onCompletion&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;CurrencyResponseBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; completion
        	               onError&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;ErrorBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; error;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;MKNetworkEngine, the parent class defines three types of block methods as below.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #a61390;"&gt;typedef&lt;/span&gt; &lt;span style="color: #a61390;"&gt;void&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;ProgressBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;double&lt;/span&gt; progress&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
&lt;span style="color: #a61390;"&gt;typedef&lt;/span&gt; &lt;span style="color: #a61390;"&gt;void&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;ResponseBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;MKNetworkOperation&lt;span style="color: #002200;"&gt;*&lt;/span&gt; operation&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
&lt;span style="color: #a61390;"&gt;typedef&lt;/span&gt; &lt;span style="color: #a61390;"&gt;void&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;ErrorBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSError&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt; error&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In our YahooEngine, we are using a new kind of block, &lt;em&gt;CurrencyResponseBlock&lt;/em&gt; that returns the exchange rate. The definition looks like this.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #a61390;"&gt;typedef&lt;/span&gt; &lt;span style="color: #a61390;"&gt;void&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;CurrencyResponseBlock&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;double&lt;/span&gt; rate&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In any normal application, you should be defining your own block methods similar to this &lt;em&gt;CurrencyResponseBlock&lt;/em&gt; for sending data back to the view controllers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Processing the data&lt;br /&gt;
Data processing, that is converting the data you fetch from your server, whether it&amp;#8217;s JSON or XML or binary plists, should be done in your Engine. Again, relieve your controllers of doing this task. Your engine should send back data only in proper model objects or arrays of model objects (in case of lists). Convert your JSON/XML to models in the engine. Again, to ensure proper separation of concerns, your view controller should not &amp;#8220;know&amp;#8221; about the &amp;#8220;keys&amp;#8221; for accessing individual elements in your JSON.&lt;/p&gt;
&lt;p&gt;That concludes the design of your Engine. Most networking framework doesn&amp;#8217;t force you to follow this separation of concerns. We do, because we care for you &lt;img src='http://blog.mugunthkumar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Method implementation&lt;br /&gt;
We will now discuss the implementation details of the method that calculates your currency exchange.&lt;/p&gt;
&lt;p&gt;Getting currency information from Yahoo, is as simple as making a GET request.&lt;br /&gt;
I wrote a macro to format this URL for a given currency pair.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #6e371a;"&gt;#define YAHOO_URL(__C1__, __C2__) [NSString stringWithFormat:@&amp;quot;d/quotes.csv?e=.csv&amp;amp;amp;f=sl1d1t1&amp;amp;amp;s=%@%@=X&amp;quot;, __C1__, __C2__]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Methods you write in your engine class should do the following in order.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Prepare your URL from the parameters.&lt;/li&gt;
&lt;li&gt;Create a MKNetworkOperation object for the request.&lt;/li&gt;
&lt;li&gt;Set your method parameters.&lt;/li&gt;
&lt;li&gt;Add completion and error handlers to the operation (The completion handler is the place to process your responses and convert them to Models.)&lt;/li&gt;
&lt;li&gt;Optionally, add progress handlers to the operation. (Or do this on the view controller)&lt;/li&gt;
&lt;li&gt;If your operation is file download, set a download stream (normally a file) to it. This is again optional.&lt;/li&gt;
&lt;li&gt;When the operation completes, process the result and invoke the block method to return this data to the calling method.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This is illustrated in the following code&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;        MKNetworkOperation &lt;span style="color: #002200;"&gt;*&lt;/span&gt;op &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self operationWithPath&lt;span style="color: #002200;"&gt;:&lt;/span&gt;YAHOO_URL&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;sourceCurrency, targetCurrency&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;
                                                  params&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #a61390;"&gt;nil&lt;/span&gt;
                                             httpMethod&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;op onCompletion&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;MKNetworkOperation &lt;span style="color: #002200;"&gt;*&lt;/span&gt;completedOperation&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;
     &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
         DLog&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;%@&amp;quot;&lt;/span&gt;, &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;completedOperation responseString&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
		 &lt;span style="color: #11740a; font-style: italic;"&gt;// do your processing here&lt;/span&gt;
         completionBlock&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;5.0f&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
     &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;onError&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSError&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt; error&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
         errorBlock&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;error&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
     &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self enqueueOperation&lt;span style="color: #002200;"&gt;:&lt;/span&gt;op&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style="color: #a61390;"&gt;return&lt;/span&gt; op;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The above code formats the URL and creates a MKNetworkOperation. After setting the completion and error handlers it queues the operation by calling the super class&amp;#8217;s enqueueOperation method and returns a reference to it. Your view controller should own this operation and cancel it when the view is popped out of the view controller hierarchy. So if you call the engine method in, say viewDidAppear, cancel the operation in viewWillDisappear. Canceling the operation will free up the queue for performing other operations in the subsequent view (Remember, only two operations can be performed in parallel on a mobile network. Canceling your operations when they are no longer needed goes a long way in ensuring performance and speed of your app).&lt;/p&gt;
&lt;p&gt;You view controller can also (optionally) add progress handlers and update the user interface. This is illustrated below.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self.uploadOperation onUploadProgressChanged&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;double&lt;/span&gt; progress&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        DLog&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;%.2f&amp;quot;&lt;/span&gt;, progress&lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #2400d9;"&gt;100.0&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
        self.uploadProgessBar.progress &lt;span style="color: #002200;"&gt;=&lt;/span&gt; progress;
    &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;MKNetworkEngine also has convenience methods to create a operation with just a URL. So the first line of code can also be written as&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;        MKNetworkOperation &lt;span style="color: #002200;"&gt;*&lt;/span&gt;op &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;self operationWithPath&lt;span style="color: #002200;"&gt;:&lt;/span&gt;YAHOO_URL&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;sourceCurrency, targetCurrency&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Do note here that request URLs are automatically prefixed with the hostname you provided while initializing your engine class.&lt;/p&gt;
&lt;p&gt;Creating a POST, DELETE or PUT method is as easy as changing the httpMethod parameter. MKNetworkEngine has more convenience methods like this. Read the header file for more.&lt;/p&gt;
&lt;span id="Example_2:"&gt;&lt;h3&gt;Example 2:&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Uploading an image to a server (TwitPic for instance).&lt;br /&gt;
Now let us go through an example of how to upload an image to a server. Uploading an image obviously requires the operation to be encoded as a multi-part form data. MKNetworkKit follows a pattern similar to ASIHttpRequest.&lt;br /&gt;
You call a method addFile:forKey: in MKNetworkOperation to &amp;#8220;attach&amp;#8221; a file as a multi-part form data to your request. It&amp;#8217;s that easy.&lt;br /&gt;
MKNetworkOperation also has a convenience method to add a image from a NSData pointer. That&amp;#8217;s you can call addData:forKey: method to upload a image to your server directly from NSData pointer. (Think of uploading a picture from camera directly).&lt;/p&gt;
&lt;span id="Example_3:"&gt;&lt;h3&gt;Example 3:&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Downloading files to a local directory (Caching)&lt;br /&gt;
Downloading a file from a remote server and saving it to a location on users&amp;#8217; iPhone is super easy with MKNetworkKit.&lt;br /&gt;
Just set the outputStream of MKNetworkOperation and you are set.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;operation setDownloadStream&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSOutputStream&lt;/span&gt;
	outputStreamToFileAtPath&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;/Users/mugunth/Desktop/DownloadedFile.pdf&amp;quot;&lt;/span&gt;
			  append&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #a61390;"&gt;YES&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can set multiple output streams to a single operation to save the same file to multiple locations (Say one to your cache directory and one to your working directory)&lt;/p&gt;
&lt;span id="Example_4:"&gt;&lt;h3&gt;Example 4:&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Image Thumbnail caching&lt;br /&gt;
For downloading images, you might probably need to provide an absolute URL rather than a path. MKNetworkEngine has a convenience method for this. Just call operationWithURLString:params:httpMethod: to create a network operation with an absolute URL.&lt;br /&gt;
MKNetworkEngine is intelligent. It coalesces multiple GET calls to the same URL into one and notifies all the blocks when that one operation completes. This drastically improves the speed of fetching your image URLs for populating thumbnails.&lt;/p&gt;
&lt;p&gt;Subclass MKNetworkEngine and override image cache directory and cache cost. If you don&amp;#8217;t want to customize these two, you can directly call MKNetworkEngine methods to download images for you. I would actually recommend you to do that.&lt;/p&gt;
&lt;span id="Caching_operations"&gt;&lt;h3&gt;Caching operations&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkKit caches all requests by default. All you need to do is to turn on caching for your Engine. When a GET request is performed, if the response was previously cached, your completion handler is called with the cached response almost immediately. To know whether the response is cached, use the isCachedResponse method. This is illustrated below.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;op onCompletion&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;MKNetworkOperation &lt;span style="color: #002200;"&gt;*&lt;/span&gt;completedOperation&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;
     &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
         &lt;span style="color: #a61390;"&gt;if&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;completedOperation isCachedResponse&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
             DLog&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;Data from cache&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
         &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
         &lt;span style="color: #a61390;"&gt;else&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
             DLog&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;Data from server&amp;quot;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
         &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
         DLog&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;@&lt;/span&gt;&lt;span style="color: #bf1d1a;"&gt;&amp;quot;%@&amp;quot;&lt;/span&gt;, &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;completedOperation responseString&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
     &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;onError&lt;span style="color: #002200;"&gt;:^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSError&lt;/span&gt;&lt;span style="color: #002200;"&gt;*&lt;/span&gt; error&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
         errorBlock&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;error&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
     &lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;span id="Freezing_operations"&gt;&lt;h3&gt;Freezing operations&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;Arguably, the most interesting feature of MKNetworkKit is built in ability to freeze operations. All you need to do is set your operation as freezable. Almost zero effort!&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;op setFreezable&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #a61390;"&gt;YES&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Freezable operations are automatically serialized when the network goes down and executed when connectivity is restored. Think of having the ability to favorite a tweet while you are offline and the operation is performed when you are online later.&lt;br /&gt;
Frozen operations are also persisted to disk when the app enters background. They will be automatically performed when the app is resumes later.&lt;/p&gt;
&lt;span id="Convenience_methods_in_MKNetworkOperation"&gt;&lt;h3&gt;Convenience methods in MKNetworkOperation&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkOperation exposes convenience methods like the following to get the format your response data.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;responseData&lt;/li&gt;
&lt;li&gt;responseString&lt;/li&gt;
&lt;li&gt;responseJSON (Only on iOS 5)&lt;/li&gt;
&lt;li&gt;responseImage&lt;/li&gt;
&lt;li&gt;responseXML&lt;/li&gt;
&lt;li&gt;error&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;They come handy when accessing the response after your network operation completes. When the format is wrong, these methods return nil. For example, trying to access responseImage when the actual response is a HTML response will return nil. The only method that is guaranteed to return the correct, expected response is responseData. Use the other methods if you are sure of the response type.&lt;/p&gt;
&lt;span id="Convenience_macros"&gt;&lt;h3&gt;Convenience macros&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;The macros, DLog and ALog were stolen unabashedly from Stackoverflow and I couldn&amp;#8217;t again find the source. If you wrote that, let me know.&lt;/p&gt;
&lt;span id="A_note_on_GCD"&gt;&lt;h3&gt;A note on GCD&lt;/h3&gt;&lt;/span&gt;
&lt;p&gt;I purposefully didn&amp;#8217;t use GCD because, network operations need to be stopped and prioritized at will. GCD, while more efficient than NSOperationQueue, cannot do this. I would recommend not to use GCD based queues for your network operations.&lt;/p&gt;
&lt;span id="Documentation"&gt;&lt;h2&gt;Documentation&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;The header files are commented and I&amp;#8217;m trying out headerdoc from Apple. Meanwhile, you can use/play around (read: Fork) with the code.&lt;/p&gt;
&lt;span id="Source_Code"&gt;&lt;h2&gt;Source Code&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;The source code for MKNetworkKit along with a demo application is available on Github.&lt;br /&gt;
&lt;a href="http://github.com/mugunthkumar/mknetworkkit"&gt;MKNetworkKit on Github&lt;/a&gt;&lt;/p&gt;
&lt;span id="Feature_requests"&gt;&lt;h2&gt;Feature requests&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Please don&amp;#8217;t email me feature requests. The best way is to &lt;a href="http://github.com/mugunthkumar/mknetworkkit/issues"&gt;create an issue on Github&lt;/a&gt;.&lt;/p&gt;
&lt;span id="Licensing"&gt;&lt;h2&gt;Licensing&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;MKNetworkKit is licensed under &lt;strong&gt;MIT License&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;All of my source code can be used free of charge in your app, provided you add the copyright notices to your app. A little mention on one of your most obscure &amp;#8220;about&amp;#8221; page will do.&lt;/p&gt;
&lt;p&gt;Attribution free licensing available upon request. Contact me at &lt;a href="mailto:mknetworkkit@mk.sg"&gt; mknetworkkit@mk.sg &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1319_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1319?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1319_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1319&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fproducts%2Fios-framework-introducing-mknetworkkit%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/ios-tutorial-advanced-networking-with-mknetworkkit/' rel='bookmark' title='iOS Tutorial: Advanced Networking with MKNetworkKit'&gt;iOS Tutorial: Advanced Networking with MKNetworkKit&lt;/a&gt; &lt;small&gt;Couple of weeks ago, I wrote a clean, fast networking...&lt;/small&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/products/introducing-my-book-ios-5-programming-pushing-the-limits/' rel='bookmark' title='Introducing my book: iOS 5 Programming Pushing the Limits'&gt;Introducing my book: iOS 5 Programming Pushing the Limits&lt;/a&gt; &lt;small&gt;iOS 5 Programming Pushing the Limits Developing Extraordinary Mobile Apps...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kaaZmE218dF0PEEjHKnFceuN70g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kaaZmE218dF0PEEjHKnFceuN70g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kaaZmE218dF0PEEjHKnFceuN70g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kaaZmE218dF0PEEjHKnFceuN70g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/G7RW0HzQu5Q" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">53</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/products/ios-framework-introducing-mknetworkkit/</feedburner:origLink></entry><entry><title type="text">Software philosophy: Release early, release often vs polished releases</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/Y_x9S-e8SDk/" /><category term="Articles" /><category term="apple" /><category term="google" /><category term="ios" /><category term="microsoft" /><category term="philosophy" /><category term="software" /><author><name>Mugunth Kumar</name></author><updated>2011-11-28T04:00:36-08:00</updated><id>http://blog.mugunthkumar.com/?p=1298</id><summary type="html">Release early, release often is a philosophy where you release the product as soon as possible and rapidly iterate it to perfection by listening to your customers. A polished release, on the other hand is where your product, in its initial version is solid, lacks obvious bugs and has just enough features to satisfy a [...]
No related posts.</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Release_early,_release_often"&gt;Release early, release often&lt;/a&gt; is a philosophy where you release the product as soon as possible and rapidly iterate it to perfection by listening to your customers. A polished release, on the other hand is where your product, in its initial version is solid, lacks obvious bugs and has just enough features to satisfy a majority of your consumers. Most software companies adopt either one of this and that choice is not superficial. In fact, it roots down to the heart of the company&amp;#8217;s ideologies.&lt;br /&gt;
Before you launch your next big product, website, app, read this and decide which side you are on.&lt;/p&gt;
&lt;span id="Philosophy_followed_by_them"&gt;&lt;h2&gt;Philosophy followed by them&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Release early, release often, has always been the mantra of Linux kernel, software from Microsoft and plenty other open source software. Microsoft (and Microsoft developers) followed this philosophy since its inception. The Windows Operating System, in the initial version (1.0) did not support overlapping windows which was a breakthrough feature on the then contemporary Macintosh. Despite that, a few years later, Microsoft was able to catch up with the competition by following the release early, release often philosophy. In 1995, the same race happened between Microsoft and Netscape with browsers. IE 1.0 was no where near Netscape, but a couple of years later, the fourth iteration of the browser, IE 4 nailed it.&lt;/p&gt;
&lt;p&gt;In late 90s, when the web became popular, updating your software (web application) became even easier and web application developers, continued to follow the same mantra. &lt;/p&gt;
&lt;p&gt;The workflow of a web developer used to be like this.&lt;/p&gt;
&lt;p&gt;Make a shitty website&lt;br /&gt;
Improve your website&lt;br /&gt;
check your visitor count&lt;br /&gt;
…&lt;br /&gt;
Improve your website&lt;br /&gt;
check your visitor count&lt;br /&gt;
…&lt;br /&gt;
…&lt;br /&gt;
Once your reach a satisfactory level, mark your release as final (remove that beta/gamma tag).&lt;/p&gt;
&lt;p&gt;Later in 2004, when Google introduced their Gmail, it was known for the perpetual beta in the logo.&lt;br /&gt;
Flickr moved from alpha to beta to gamma(!) in 2006!&lt;/p&gt;
&lt;span id="Philosophy_followed_by_Apple"&gt;&lt;h2&gt;Philosophy followed by Apple&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Apple on the other hand polish their products to perfection. May be it&amp;#8217;s their &amp;#8220;Think different&amp;#8221; culture or may be it&amp;#8217;s the ingrained attitude of the late founder, Steve Jobs, to make &amp;#8220;insanely great&amp;#8221; products relegating profits or business strategies.&lt;/p&gt;
&lt;p&gt;The first version of iOS (then called as iPhone OS), did not even have MMS, included in even the dumbest phones out there. Yet, every feature that was available, worked really really well. The first iPod, despite being available only for Mac users, was a runaway success.&lt;/p&gt;
&lt;span id="Consumer_mindset_outside_of_Software"&gt;&lt;h2&gt;Consumer mindset outside of Software&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Let&amp;#8217;s for a moment think outside of Software. Let&amp;#8217;s take movies for example. Every single release of a movie, whether it is The Jurassic Park and its sequels or The Matrix and its sequels or Steve Jobs&amp;#8217;s own Toy Story and its sequels never had &amp;#8220;versions&amp;#8221;.&lt;br /&gt;
The movies were great right from the first release and the producers and directors never &amp;#8220;planned&amp;#8221; to make their movie incrementally better. Of course there were sequels, but they were not &amp;#8220;bug fixes&amp;#8221; or incremental updates to the original movie. The same holds good for physical commodities like cars or cameras. Remember, the world had cars, cameras and movies, much before Software. So, how and why did people got accustomed to this way of life, when it comes to Software? Will you accept if your new car, in its &amp;#8220;version 1.0&amp;#8243; doesn&amp;#8217;t speed up beyond 60? Will you accept if the car manufacturer promises a free  &amp;#8220;engine update&amp;#8221; in the &amp;#8220;near future&amp;#8221;?&lt;/p&gt;
&lt;p&gt;The reason was partly because, at least in the past, software was considered &amp;#8220;Magical&amp;#8221;. The first spreadsheet program (Lotus 1-2-3) can &amp;#8220;sort&amp;#8221; the marks of student in ascending order and made the process of calculating the rank among students in a class, super easy, fast and reliable. What usually took days, was accomplished within seconds using Software. Other commodities did not provide this level of satisfaction. &lt;/p&gt;
&lt;p&gt;When something performs well on one area, human beings tend to be lenient in evaluating its performance else where. That &amp;#8220;something&amp;#8221; can be anything. &lt;a href="http://www.youtube.com/watch?v=7xYkiN4-gl8"&gt;A beautiful blonde girl who is &amp;#8220;not so smart&amp;#8221;&lt;/a&gt; or a restaurant that serves tasty food, but looks shoddy (or the other way round). This is precisely what happened to user&amp;#8217;s perception of Software decades ago and unfortunately, has been continuing till now. A software that does one thing (sorting in this case) properly, but crashes often was still acceptable.&lt;/p&gt;
&lt;span id="How_Apple_changed_your_consumers"&gt;&lt;h2&gt;How Apple changed your consumers&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Apple, on the other hand, tend to think different&lt;strong&gt;ly&lt;/strong&gt;&lt;em&gt;&lt;/em&gt;. They never use the &amp;#8220;beta&amp;#8221; tag. (And when they do, it is &lt;a href="http://www.youtube.com/watch?v=SHoukZpMhDE"&gt;still better than the competition&lt;/a&gt;). Look at the iterative changes that happens to any of their product. It, mostly remains same. The first iPod, still looks closely similar to the latest generation iPod classic and the first iPhone looks closely similar to the latest iPhone, the iPhone 4S and Mac OS X 10.0, looks closely similar to Mac OS X Lion. Leave software, even the light bulb invented by Edison a century ago, looks very similar in shape and size compared to the tungsten filament light bulb today. Contrarily, compare that to the control panel on Windows 95 to Windows 7 and the upcoming Windows 8 beta. It&amp;#8217;s clear that, Microsoft didn&amp;#8217;t nail it and they &lt;strong&gt;still&lt;/strong&gt; haven&amp;#8217;t nailed it.&lt;/p&gt;
&lt;p&gt;With iPod, iPhone, iPad and several other products, Apple has proved that, Software can be done right, right from the initial version and has re-wired users&amp;#8217; brain to expect quality products even when it is Software. This can be seen on the ratings of same apps from the same companies on Apple App Store and Android Market Place. Ratings on Market Place is usually higher than on App Store even if the Android version is buggier. Apple users expect quality. They don&amp;#8217;t tolerate sh*t.&lt;/p&gt;
&lt;p&gt;These two philosophical differences might have stemmed from the thought process of Steve Jobs and Bill Gates who shaped the early software industry. Steve was a perfectionist. Anything less than the ultimate is a shitty product. Bill on the other hand was different. He was more focussed on the monetary aspects of things (that doesn&amp;#8217;t automatically mean it&amp;#8217;s bad) at the expense of quality. &lt;/p&gt;
&lt;span id="What_should_you_do"&gt;&lt;h2&gt;What should you do?&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;The release early, release often mantra has created a notion that Software is unreliable and often buggy. Since most software are like that, consumers, more than not, aren&amp;#8217;t willing to pay for Software just as easy as they would for anything else. When we learn this, we complain that, their attitude is wrong. We even go as far as comparing the cost of a Starbucks coffee to an app and say people don&amp;#8217;t pay for software that costs a fraction of the price of a coffee. It&amp;#8217;s not that people don&amp;#8217;t want to pay. It&amp;#8217;s more like, people are not interested in paying for something that they are afraid, might not work as advertised. To consumers, buying a software is more like taking a risk than buying a coffee. With Windows, the risk was viruses. With online, cloud only, web applications, it was privacy. With App Store, Apple has shown them, what trustworthy computing is mitigating a huge risk considerably. With App Store, the risk a customer takes is paying for a software that doesn&amp;#8217;t work as advertised (or doesn&amp;#8217;t meet the quality expectations).&lt;/p&gt;
&lt;p&gt;While Apple was not doing well in late 90s, the industry thrived well on release early, release often mantra. It often worked since, funding the software product was easy when it was iteratively developed. But, it&amp;#8217;s 2011 now. If you are making a iOS app, remember that your target audience are iPhone/iPad users. They don&amp;#8217;t tolerate sh*t. The App Store is filled with high quality apps and if your app doesn&amp;#8217;t meet that quality expectations, don&amp;#8217;t expect a run away success.  Make a polished product from day 1. If you are running low on budget/funding, don&amp;#8217;t write software in the first place. If you were a movie producer, you can&amp;#8217;t make a movie with half the money, release it and build upon that. Neither movies, nor cars or any other commodities are made like that. Don&amp;#8217;t make a 0.8b release and expect users to tolerate it. Don&amp;#8217;t promise *big* features on upcoming release. Some companies that I admire are Tapbots, Panic Software (they make the awesome FTP client, Transmit), AgileBits (the guys behind 1password). All of their products are &amp;#8220;insanely great&amp;#8221; right from day 1. Just because, something can be changed easily, doesn&amp;#8217;t mean you should be changed frequently (iterated) even after release. Movies too had iterations, and cars had prototypes, but they existed only within the studio or the factory and never made it to the customers. You and me, the common man, doesn&amp;#8217;t even know of their existence. Why can&amp;#8217;t we build software like that? Why should you ship a product that&amp;#8217;s not complete?&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s kill the notion that software can be made great &lt;strong&gt;only&lt;/strong&gt; by rapid iteration. Make your next product an example of that.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1298_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1298?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1298_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1298&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Farticles%2Fsoftware-philosophy-release-early-release-often-vs-polished-releases%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;No related posts.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pblEOxLs5teRz18aXsEjX7qRSGc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pblEOxLs5teRz18aXsEjX7qRSGc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pblEOxLs5teRz18aXsEjX7qRSGc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pblEOxLs5teRz18aXsEjX7qRSGc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/Y_x9S-e8SDk" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/articles/software-philosophy-release-early-release-often-vs-polished-releases/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">7</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/articles/software-philosophy-release-early-release-often-vs-polished-releases/</feedburner:origLink></entry><entry><title type="text">iOS Code: MKiCloudSync – Sync your NSUserDefaults to iCloud with a single line of code</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/1gZRp5Kst5E/" /><category term="Coding" /><category term="Featured Articles" /><category term="code" /><category term="iCloud" /><category term="ios" /><category term="ios 5" /><author><name>Mugunth Kumar</name></author><updated>2011-11-19T21:33:32-08:00</updated><id>http://blog.mugunthkumar.com/?p=1308</id><summary type="html">Just wrote this class, MKiCloudSync (100 lines of code) that auto syncs your NSUserDefaults to iCloud. How to use? All you need to do is to enable iCloud key value store entitlements, copy the files and forget about the rest. Step 1: Enable iCloud entitlements for your app. This is easily done in Xcode 4.2.1 [...]
Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/using-mkstorekit-in-your-apps/' rel='bookmark' title='Using MKStoreKit in your apps'&gt;Using MKStoreKit in your apps&lt;/a&gt; &lt;small&gt;MKStoreKit, as you probably know is a framework for implementing...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;Just wrote this class, MKiCloudSync (100 lines of code) that auto syncs your NSUserDefaults to iCloud.&lt;/p&gt;
&lt;span id="How_to_use"&gt;&lt;h2&gt;How to use?&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;All you need to do is to enable iCloud key value store entitlements, copy the files and forget about the rest.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Enable iCloud entitlements for your app. This is easily done in Xcode 4.2.1 by opening your target settings and checking &amp;#8220;Enable Entitlements&amp;#8221; from the summary tab.&lt;/p&gt;
&lt;p&gt;This is illustrated below.&lt;/p&gt;
&lt;p&gt;&lt;div class="wp-caption aligncenter" style="width: 610px"&gt;&lt;img style="border-style: initial; border-color: initial; border-width: 0px;" title="Xcode.png" src="http://blog.mugunthkumar.com/wp-content/uploads/Xcode.png" alt="Xcode" width="600" height="378" border="0" /&gt;&lt;p class="wp-caption-text"&gt;Enabling iCloud Entitlements in Xcode 4.2.1&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;strong&gt;Tip: &lt;/strong&gt;&lt;br /&gt;
If you are sharing settings with other apps, ensure that your iCloud Key-Value Store is the same across all those apps.&lt;br /&gt;
&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;br /&gt;
Drag the two files&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MKiCloudSync.h&lt;/li&gt;
&lt;li&gt;MKiCloudSync.m &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;into your project. You can find these files in the Source Code section of this post.&lt;br /&gt;
&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;br /&gt;
In your applicationDidFinishLaunchingWithOptions: method,&lt;br /&gt;
start the sync by calling,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;MKiCloudSync start&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You also have to #include the header file.&lt;br /&gt;
This is probably the only line of code you have to write!&lt;br /&gt;
&lt;strong&gt;Step 4:&lt;/strong&gt;&lt;br /&gt;
Sleep… Kidding.&lt;/p&gt;
&lt;p&gt;There is no step 4. Continue using NSUserDefaults to save your settings. The MKiCloudSync class automatically syncs your settings to iCloud and restores them back to your NSUserDefaults when they are changed on other devices.&lt;/p&gt;
&lt;p&gt;To top them all, it also posts a notification,&lt;/p&gt;
&lt;pre&gt;kMKiCloudSyncNotification&lt;/pre&gt;
&lt;p&gt;to let you know that a sync has been performed. You can listen to this notification and update your user interface from NSUserDefaults.&lt;/p&gt;
&lt;span id="Advantages"&gt;&lt;h2&gt;Advantages&lt;/h2&gt;&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;Upgrading your existing iOS 4 apps to sync settings to iCloud is now super easy.&lt;/li&gt;
&lt;li&gt;With this class, you no longer have to add calls to NSUbiquitousKeyValueStore throughout your app. You can continue your existing method of saving them to NSUserDefaults. Everything is automatic. If your settings might change often, you can observe the notification &lt;strong&gt;&lt;em&gt;kMKiCloudSyncNotification&lt;/em&gt;&lt;/strong&gt; and update your user interface.&lt;/li&gt;
&lt;/ul&gt;
&lt;span id="Source_Code"&gt;&lt;h2&gt;Source Code&lt;/h2&gt;&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/MugunthKumar/MKiCloudSync"&gt;MKiCloudSync on Github&lt;/a&gt;
&lt;/ul&gt;
&lt;span id="Licensing"&gt;&lt;h2&gt;Licensing&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Royalty free for commercial or non-commercial use, though attribution will please me to write more such code &lt;img src='http://blog.mugunthkumar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /&gt; &lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1308_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1308?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1308_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1308&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fios-code-mkicloudsync-sync-your-nsuserdefaults-to-icloud-with-a-single-line-of-code%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/using-mkstorekit-in-your-apps/' rel='bookmark' title='Using MKStoreKit in your apps'&gt;Using MKStoreKit in your apps&lt;/a&gt; &lt;small&gt;MKStoreKit, as you probably know is a framework for implementing...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zkLig2DdT-2z6UKz10nglhP23vc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zkLig2DdT-2z6UKz10nglhP23vc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zkLig2DdT-2z6UKz10nglhP23vc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zkLig2DdT-2z6UKz10nglhP23vc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/1gZRp5Kst5E" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/coding/ios-code-mkicloudsync-sync-your-nsuserdefaults-to-icloud-with-a-single-line-of-code/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">21</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/coding/ios-code-mkicloudsync-sync-your-nsuserdefaults-to-icloud-with-a-single-line-of-code/</feedburner:origLink></entry><entry><title type="text">Easy Debugging with NSMutableURLRequest</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/fv2WS1m_ICY/" /><category term="Coding" /><category term="curl" /><category term="debugging" /><category term="description" /><category term="ios5" /><category term="nsmutableurlrequest" /><category term="snippet" /><category term="tip" /><author><name>Mugunth Kumar</name></author><updated>2011-11-07T03:30:36-08:00</updated><id>http://blog.mugunthkumar.com/?p=1291</id><summary type="html">This post is a sequel to one of my previous post, Easy Debugging with ASIHTTPRequest. I previously showed you a code snippet for logging ASIHTTPRequest as curl commands on command line. I&amp;#8217;ve updated that code for NSMutableURLRequest, which means, you can use it for almost any third party networking kits, including the recently famous AFNetworking. [...]
Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/easy-debugging-with-asihttprequest/' rel='bookmark' title='Easy Debugging with ASIHTTPRequest'&gt;Easy Debugging with ASIHTTPRequest&lt;/a&gt; &lt;small&gt;Just wrote this quick and dirty method that dumps a...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;This post is a sequel to one of my previous post, &lt;a href="http://blog.mugunthkumar.com/coding/easy-debugging-with-asihttprequest/"&gt;Easy Debugging with ASIHTTPRequest&lt;/a&gt;.&lt;br /&gt;
I previously showed you a code snippet for logging ASIHTTPRequest as curl commands on command line.&lt;br /&gt;
I&amp;#8217;ve updated that code for NSMutableURLRequest, which means, you can use it for almost any third party networking kits, including the recently famous AFNetworking.&lt;/p&gt;
&lt;span id="The_Drive"&gt;&lt;h2&gt;The Drive&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;The main necessity for this was, I always used to miss some of the parameters I should use for calling a said API. The only way to debug these issues is to simulate the call on a third party REST client, check if everything works and then start coding. But that was a bit too overkill for me. I wrote this snippet so that, you can straight away NSLog a NSMutableURLRequest and see the curl syntax on the console. You can copy and paste this to your Terminal and check if you are calling the API correctly.&lt;/p&gt;
&lt;span id="Usage"&gt;&lt;h2&gt;Usage&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Drag the attached files into your project.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&amp;lt;code&amp;gt;NSMutableURLRequest&lt;span style="color: #002200;"&gt;+&lt;/span&gt;CurlDescription.h
&lt;span style="color: #400080;"&gt;NSMutableURLRequest&lt;/span&gt;&lt;span style="color: #002200;"&gt;+&lt;/span&gt;CurlDescription.m&amp;lt;&lt;span style="color: #002200;"&gt;/&lt;/span&gt;code&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Add a line to your PCH file or any global header file to include this file.&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s it!. You are done.&lt;br /&gt;
Now, whenever you need to print your request as a curl command, just add a NSLog it.&lt;/p&gt;
&lt;p&gt;If you are using &lt;a href="https://github.com/gowalla/AFNetworking"&gt;AFNetworking&lt;/a&gt;, I would recommend overriding the method,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;enqueueHTTPRequestOperationWithRequest&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSURLRequest&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;urlRequest 
                                       success&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;id&lt;/span&gt; object&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;success 
                                       failure&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSHTTPURLResponse&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;response, &lt;span style="color: #400080;"&gt;NSError&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;error&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;failure;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;in your own APIClient class.&lt;br /&gt;
You can now NSLog the request and call the super class implementation.&lt;/p&gt;
&lt;span id="Example"&gt;&lt;h2&gt;Example&lt;/h2&gt;&lt;/span&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #002200;"&gt;-&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt; enqueueHTTPRequestOperationWithRequest&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSURLRequest&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;request success&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;id&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;success failure&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #a61390;"&gt;void&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #002200;"&gt;^&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSHTTPURLResponse&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;, &lt;span style="color: #400080;"&gt;NSError&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;failure &lt;span style="color: #002200;"&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    NSLog&lt;span style="color: #002200;"&gt;&amp;#40;&lt;/span&gt;request&lt;span style="color: #002200;"&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;super enqueueHTTPRequestOperationWithRequest&lt;span style="color: #002200;"&gt;:&lt;/span&gt;request success&lt;span style="color: #002200;"&gt;:&lt;/span&gt;success failure&lt;span style="color: #002200;"&gt;:&lt;/span&gt;failure&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;
&lt;span style="color: #002200;"&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This would log every single API call you make in your app on the console as a curl command.&lt;br /&gt;
A second advantage of this is, it reduces&lt;em&gt; cognitive overload&lt;/em&gt;. When you see the request printed on console, you don&amp;#8217;t have to think what it is doing. Just copy and paste it to Terminal and start debugging right away! &lt;/p&gt;
&lt;span id="Source_Code_"&gt;&lt;h2&gt;Source Code &lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;&lt;a href="http://blog.mugunthkumar.com/wp-content/uploads/NSMutableURLRequest+Curl.zip" title="NSMutableURLRequest+Curl.zip" alt="NSMutableURLRequest+Curl"&gt;NSMutableURLRequest+Curl.zip&lt;/a&gt;&lt;/p&gt;
&lt;span id="Licensing"&gt;&lt;h2&gt;Licensing&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;Do whatever you want with the code without removing the source code attribution.&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;br /&gt;
Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1291_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1291?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1291_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1291&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Feasy-debugging-with-nsmutableurlrequest%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/easy-debugging-with-asihttprequest/' rel='bookmark' title='Easy Debugging with ASIHTTPRequest'&gt;Easy Debugging with ASIHTTPRequest&lt;/a&gt; &lt;small&gt;Just wrote this quick and dirty method that dumps a...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/r4gjzp8aHpMwradh970DhIxXhJk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/r4gjzp8aHpMwradh970DhIxXhJk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/r4gjzp8aHpMwradh970DhIxXhJk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/r4gjzp8aHpMwradh970DhIxXhJk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/fv2WS1m_ICY" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/coding/easy-debugging-with-nsmutableurlrequest/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">0</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/coding/easy-debugging-with-nsmutableurlrequest/</feedburner:origLink></entry><entry><title type="text">iOS5: Migrating your code to NSJSONSerialization using the Adapter Design Pattern</title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/MugunthKumar/~3/inwMGT5lkHw/" /><category term="Coding" /><category term="ios5" /><category term="json" /><category term="json-framework" /><category term="JSONKit" /><category term="touchJSON" /><author><name>Mugunth Kumar</name></author><updated>2011-10-24T20:20:59-07:00</updated><id>http://blog.mugunthkumar.com/?p=1169</id><summary type="html">In iOS 5, Apple introduced NSJSONSerialization, for parsing JSON strings. But, as on date, you might have already developed your app using a third party component like JSONKit or json-framework or TouchJSON and you might not want to migrate your complete code base to NSJSONSerialization. In fact removing or replacing an existing framework is not [...]
Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/in-app-purchases-troubleshooting-code0-cannot-connect-to-itunes-store-skerrorunknown/' rel='bookmark' title='In App Purchases: Troubleshooting Code=0 &amp;#8220;Cannot connect to iTunes Store&amp;#8221; (SKErrorUnknown)'&gt;In App Purchases: Troubleshooting Code=0 &amp;#8220;Cannot connect to iTunes Store&amp;#8221; (SKErrorUnknown)&lt;/a&gt; &lt;small&gt;When using MKStoreKit or any other equivalent framework or regular...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;</summary><content type="html">&lt;p&gt;&lt;/p&gt;&lt;p&gt;In iOS 5, Apple introduced NSJSONSerialization, for parsing JSON strings.&lt;/p&gt;
&lt;p&gt;But, as on date, you might have already developed your app using a third party component like JSONKit or json-framework or TouchJSON and you might not want to migrate your complete code base to NSJSONSerialization. In fact removing or replacing an existing framework is not really an easy thing especially if you have a lot of dependencies. However, moving towards Apple&amp;#8217;s implementation is always safer to use since you have the guarantee that it will be maintained kept up to date.&lt;/p&gt;
&lt;span id="The_Adapter_Design_Pattern"&gt;&lt;h2&gt;The Adapter Design Pattern&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;This is where the &lt;a href="http://en.wikipedia.org/wiki/Adapter_pattern"&gt;Adapter design pattern&lt;/a&gt; comes to rescue.&lt;br /&gt;
Adapters are classes that helps in migrating your code base with as low side-effects as possible. If you were depending on the class categories in your third party framework, which is probably the case, you can use my &amp;#8220;adapter&amp;#8221; classes to route those messages to Apple&amp;#8217;s framework. That way, all you need to do is to copy couple of files from my framework, and ditch your third party json parsing frameworks. It should all start working automatically.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s see how that works.&lt;/p&gt;
&lt;p&gt;The adapter classes I wrote &amp;#8220;adapts&amp;#8221; your code to use Apple&amp;#8217;s NSJSONSerialization instead of your third party framework. Did I say that the whole adapter classes run under a hundred lines of code?&lt;br /&gt;
For example, if you call JSONValue of json-framework in your code like this,&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="objc" style="font-family:monospace;"&gt;&lt;span style="color: #400080;"&gt;NSString&lt;/span&gt; &lt;span style="color: #002200;"&gt;*&lt;/span&gt;jsonString &lt;span style="color: #002200;"&gt;=&lt;/span&gt; &lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #400080;"&gt;NSString&lt;/span&gt; stringWithContentsOfURL&lt;span style="color: #002200;"&gt;:&lt;/span&gt;@http&lt;span style="color: #002200;"&gt;:&lt;/span&gt;&lt;span style="color: #11740a; font-style: italic;"&gt;//example.com/test.json&amp;quot;];&lt;/span&gt;
&lt;span style="color: #002200;"&gt;&amp;#91;&lt;/span&gt;jsonString JSONValue&lt;span style="color: #002200;"&gt;&amp;#93;&lt;/span&gt;;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;my adapter routes the &amp;#8220;JSONValue&amp;#8221; extension method to Apple&amp;#8217;s implementation. The adapter classes have similar implementations for every similar category method in the framework.&lt;/p&gt;
&lt;span id="Source_Code"&gt;&lt;h2&gt;Source Code&lt;/h2&gt;&lt;/span&gt;
&lt;p&gt;The source code is pretty elementary right now and supports only json-framework. and I&amp;#8217;m maintaining them on Github here.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/MugunthKumar/third-party-json-adapters"&gt;https://github.com/MugunthKumar/third-party-json-adapters&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Expecting volunteers to write equivalent adapters for other frameworks (especially for frameworks that are slower than Apple&amp;#8217;s)&lt;/p&gt;
&lt;p&gt;&amp;#8211;&lt;/p&gt;
&lt;p&gt;Mugunth&lt;/p&gt;
&lt;p&gt;&lt;map name='google_ad_map_1169_8b86e81420c6776e'&gt;
&lt;area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/1169?pos=0' coords='1,2,367,28' /&gt;
&lt;area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/&gt;&lt;/map&gt;
&lt;img usemap='#google_ad_map_1169_8b86e81420c6776e' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;amp;client=&amp;amp;channel=&amp;amp;output=png&amp;amp;cuid=1169&amp;amp;url= http%3A%2F%2Fblog.mugunthkumar.com%2Fcoding%2Fios5-migrating-your-code-to-nsjsonserializer-using-the-adapter-design-pattern%2F' /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href ="http://twitter.com/mugunthkumar"&gt;Follow me &lt;/a&gt; on Twitter&lt;/p&gt;&lt;p&gt;&amp;copy;2012 &lt;a href="http://blog.mugunthkumar.com"&gt;MKBlog&lt;/a&gt;. All Rights Reserved.&lt;/p&gt;.
&lt;p&gt;Related posts:&lt;ol&gt;
&lt;li&gt;&lt;a href='http://blog.mugunthkumar.com/coding/in-app-purchases-troubleshooting-code0-cannot-connect-to-itunes-store-skerrorunknown/' rel='bookmark' title='In App Purchases: Troubleshooting Code=0 &amp;#8220;Cannot connect to iTunes Store&amp;#8221; (SKErrorUnknown)'&gt;In App Purchases: Troubleshooting Code=0 &amp;#8220;Cannot connect to iTunes Store&amp;#8221; (SKErrorUnknown)&lt;/a&gt; &lt;small&gt;When using MKStoreKit or any other equivalent framework or regular...&lt;/small&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/paB6zyNA9a1aVxKgp_qt5LkDb18/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/paB6zyNA9a1aVxKgp_qt5LkDb18/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/paB6zyNA9a1aVxKgp_qt5LkDb18/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/paB6zyNA9a1aVxKgp_qt5LkDb18/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/MugunthKumar/~4/inwMGT5lkHw" height="1" width="1"/&gt;</content><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blog.mugunthkumar.com/coding/ios5-migrating-your-code-to-nsjsonserializer-using-the-adapter-design-pattern/feed/</wfw:commentRss><slash:comments xmlns:slash="http://purl.org/rss/1.0/modules/slash/">0</slash:comments><feedburner:origLink>http://blog.mugunthkumar.com/coding/ios5-migrating-your-code-to-nsjsonserializer-using-the-adapter-design-pattern/</feedburner:origLink></entry></feed>

