<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Feelin' Fine - Tutorials</title>
    <link>http://blog.proculo.de/</link>
    <description>Macs &amp; more</description>
    <dc:language>en</dc:language>
    <admin:errorReportsTo rdf:resource="mailto:lex@proculo.de" />
    <generator>Serendipity 1.2.1 - http://www.s9y.org/</generator>
    
    <image>
        <url>http://blog.proculo.de/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Feelin' Fine - Tutorials - Macs &amp; more</title>
        <link>http://blog.proculo.de/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Using KVO to annotate UISliders</title>
    <link>http://blog.proculo.de/archives/182-Using-KVO-to-annotate-UISliders.html</link>
            <category>Tutorials</category>
    
    <comments>http://blog.proculo.de/archives/182-Using-KVO-to-annotate-UISliders.html#comments</comments>
    <wfw:comment>http://blog.proculo.de/wfwcomment.php?cid=182</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://blog.proculo.de/rss.php?version=2.0&amp;type=comments&amp;cid=182</wfw:commentRss>
    

    <author>alexander.repty@mac.com (Alexander Repty)</author>
    <content:encoded>
    &lt;div class=&quot;serendipity_imageComment_left&quot; style=&quot;width: 83px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a  class=&#039;serendipity_image_link&#039;  rel=&#039;lightbox&#039; href=&#039;http://blog.proculo.de/uploads/FolioCasePaging.jpg&#039;&gt;&lt;!-- s9ymdb:178 --&gt;&lt;img width=&quot;83&quot; height=&quot;110&quot; src=&quot;http://blog.proculo.de/uploads/FolioCasePaging.serendipityThumb.jpg&quot; alt=&quot;&quot;  /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;Annotated UISlider in Folio Case&lt;/div&gt;&lt;/div&gt;In &lt;a href=&quot;http://foliocaseapp.com&quot;&gt;Folio Case&lt;/a&gt;, I&#039;m using a custom UISlider with annotations to allow users to easily skim through the document and find the page they want. When the user taps the knob, a small bubble shows up that shows the page number that corresponds to the position where the knob currently is. The page number within the bubble is constantly updated as the user drags the knob around. When the user lets go, the app turns to the selected page, the knob snaps in place and the bubble slowly fades out. This approach makes sure that the user gets the information when he/she needs it and it doesn&#039;t stand in the way of getting things done. &lt;br /&gt;
&lt;br /&gt;
Ever since &lt;a href=&quot;http://foliocaseapp.com&quot;&gt;Folio Case&lt;/a&gt; was released, I&#039;ve been asked how I achieved this effect, as there is no built-in functionality for this behaviour in UIKit. The short answer is: using KVO (key value observing), I track whether the knob is being touched and moved and react appropriately.&lt;br /&gt;
&lt;br /&gt;
The long answer is, well, longer. If you&#039;re not familiar with the concept of KVO, you might want to read Apple&#039;s &lt;a href=&quot;http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html&quot;&gt;Key Value Observing Programming Guide&lt;/a&gt;. In short, Apple describes KVO as &quot;a mechanism that allows objects to be notified of changes to specific properties of other objects&quot;. In practical use, this means that I can register as an observer to any property other classes expose, such as a UIView&#039;s frame. If I choose to do so, I will be notified whenever the object is being moved within its superview, which causes its frame to change.&lt;br /&gt;
&lt;br /&gt;
Now, in order to track a UISlider&#039;s knob movement, we will have to get a little tricky. A UISlider instance, once it is being displayed on the screen, has three subviews, all of which are instances of UIImageView. The third and foremost UIImageView instance contains the UISlider&#039;s knob. This might change at any time, so if you&#039;re going to use an approach like this in production code, be aware that it might change with the next release of iOS. However, the worst thing that can happen in this case is that the bubble won&#039;t be shown anymore.&lt;br /&gt;
&lt;br /&gt;
In &lt;code&gt;ARAnnotatedSliderView&lt;/code&gt;, which is my class to manage the UISlider and the bubble that is being conditionally displayed, I have the following method:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://gist.github.com/595211.js&quot;&gt; &lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;kARPageScrubberViewKeypathFrame&lt;/code&gt; and &lt;code&gt;kARPageScrubberViewKeypathTracking&lt;/code&gt; are simple constant NSStrings, &lt;code&gt;@&quot;frame&quot;&lt;/code&gt; and &lt;code&gt;@&quot;tracking&quot;&lt;/code&gt;, respectively.  The first property I want to observe is the knob&#039;s frame, to be notified of changes in the knob&#039;s positioning. The second property I want to observe is the UISlider&#039;s &lt;i&gt;tracking&lt;/i&gt; property, to be notified when the user starts tracking the knob with his/her finger and when they stop, so I can dismiss the bubble. When one of those notifications kicks in, I react to it using this method:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://gist.github.com/595226.js&quot;&gt; &lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
When the knob&#039;s frame was changed, this code makes sure that the bubble view stays right on top of it to ensure a smooth experience for the user. When tracking starts, I can use this notification to display the bubble, and when tracking stops, I can set up a timer to dismiss the bubble after a short while.&lt;br /&gt;
&lt;br /&gt;
As you can see from the complete code, this class is taken from &lt;a href=&quot;http://foliocaseapp.com&quot;&gt;Folio Case&lt;/a&gt; without (many) changes, and so is not well configurable. The bubble will always display &quot;Page %d&quot; where a class that was intended as being reusable would probably allow you to customize this setting. I&#039;ve set up a &lt;a href=&quot;http://github.com/alexrepty/ARAnnotatedSlider&quot;&gt;small example project for this on Github&lt;/a&gt;, if you&#039;d like to check it out and play with it. If someone ends up making a fully reusable class out of this, please let me know.&lt;br /&gt;
&lt;br /&gt;
If you&#039;d like to get back to me, feel free to leave a comment here or &lt;a href=&quot;http://twitter.com/arepty/&quot;&gt;follow me on Twitter&lt;/a&gt;. 
    </content:encoded>

    <pubDate>Fri, 24 Sep 2010 13:14:30 +0200</pubDate>
    <guid isPermaLink="false">http://blog.proculo.de/archives/182-guid.html</guid>
    
</item>
<item>
    <title>Paging-enabled UIScrollView With Previews</title>
    <link>http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html</link>
            <category>Tutorials</category>
    
    <comments>http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html#comments</comments>
    <wfw:comment>http://blog.proculo.de/wfwcomment.php?cid=180</wfw:comment>

    <slash:comments>10</slash:comments>
    <wfw:commentRss>http://blog.proculo.de/rss.php?version=2.0&amp;type=comments&amp;cid=180</wfw:commentRss>
    

    <author>alexander.repty@mac.com (Alexander Repty)</author>
    <content:encoded>
    &lt;p&gt;&lt;div class=&quot;serendipity_imageComment_left&quot; style=&quot;width: 45px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a  class=&#039;serendipity_image_link&#039;  rel=&#039;lightbox&#039; href=&#039;http://blog.proculo.de/uploads/AppStoreGroceries.png&#039;&gt;&lt;!-- s9ymdb:174 --&gt;&lt;img width=&quot;45&quot; height=&quot;110&quot; src=&quot;http://blog.proculo.de/uploads/AppStoreGroceries.serendipityThumb.png&quot; alt=&quot;&quot;  /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;App Store&lt;/div&gt;&lt;/div&gt;In some of the applications that come with the iPhone, such as the App Store and Mobile Safari, Apple uses a technique for paging-enabled &lt;code&gt;UIScrollViews&lt;/code&gt; that show a little bit of the neighbouring pieces of content instead of displaying a single view controller over the whole width of the screen.  I think those previews are a really great UI element, since they&#039;re much easier to spot than the &lt;code&gt;UIPageControl&lt;/code&gt; which usually sits right below the UIScrollView. It shows the user that there is more (or no more) content right next to what they are currently seeing.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;&lt;div class=&quot;serendipity_imageComment_left&quot; style=&quot;width: 45px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a  class=&#039;serendipity_image_link&#039;  rel=&#039;lightbox&#039; href=&#039;http://blog.proculo.de/uploads/Safari.png&#039;&gt;&lt;!-- s9ymdb:175 --&gt;&lt;img width=&quot;45&quot; height=&quot;110&quot; src=&quot;http://blog.proculo.de/uploads/Safari.serendipityThumb.png&quot; alt=&quot;&quot;  /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;Mobile Safari&lt;/div&gt;&lt;/div&gt;If you&#039;ve ever used &lt;code&gt;UIScrollView&lt;/code&gt;&#039;s &lt;code&gt;pagingEnabled&lt;/code&gt; property, you probably know that this is not easily doable. The &lt;code&gt;UIScrollView&lt;/code&gt; will stop only at multiples of its frame&#039;s width and cannot be configured to stop at shorter intervals. I recently needed to implement a paging-enabled &lt;code&gt;UIScrollView&lt;/code&gt; and was trying to replicate this behaviour and found a way to implement these previews.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html&quot;&gt;Read on for the full tutorial.&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;&lt;a href=&quot;http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html#extended&quot;&gt;Continue reading &quot;Paging-enabled UIScrollView With Previews&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Fri, 12 Feb 2010 17:14:00 +0100</pubDate>
    <guid isPermaLink="false">http://blog.proculo.de/archives/180-guid.html</guid>
    
</item>
<item>
    <title>Attaching a UIToolbar to the iPhone's Keyboard</title>
    <link>http://blog.proculo.de/archives/178-Attaching-a-UIToolbar-to-the-iPhones-Keyboard.html</link>
            <category>Tutorials</category>
    
    <comments>http://blog.proculo.de/archives/178-Attaching-a-UIToolbar-to-the-iPhones-Keyboard.html#comments</comments>
    <wfw:comment>http://blog.proculo.de/wfwcomment.php?cid=178</wfw:comment>

    <slash:comments>5</slash:comments>
    <wfw:commentRss>http://blog.proculo.de/rss.php?version=2.0&amp;type=comments&amp;cid=178</wfw:commentRss>
    

    <author>alexander.repty@mac.com (Alexander Repty)</author>
    <content:encoded>
    One nifty little &lt;a href=&quot;http://www.apple.com/iphone/&quot;&gt;iPhone&lt;/a&gt; feature that left an impression with me is the way that the keyboard in the &quot;&lt;a href=&quot;http://www.apple.com/iphone/iphone-3gs/messages.html&quot;&gt;Messages&lt;/a&gt;&quot; application slides in and out with the keyboard, as if it were attached to it - but it isn&#039;t. I needed a similar feature for an app that I&#039;m currently working on for a client, so I decided to investigate how to implement this feature in my own stuff.&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;&lt;div class=&quot;serendipity_imageComment_left&quot; style=&quot;width: 142px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a  class=&#039;serendipity_image_link&#039;  rel=&#039;lightbox&#039; href=&#039;http://blog.proculo.de/uploads/Messages_NoKeyboard.png&#039;&gt;&lt;!-- s9ymdb:168 --&gt;&lt;img width=&quot;71&quot; height=&quot;110&quot; src=&quot;http://blog.proculo.de/uploads/Messages_NoKeyboard.serendipityThumb.png&quot; alt=&quot;&quot;  /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;Viewing messages, keyboard not shown.&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_left&quot; style=&quot;width: 142px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a  class=&#039;serendipity_image_link&#039;  rel=&#039;lightbox&#039; href=&#039;http://blog.proculo.de/uploads/Messages_WithKeyboard.png&#039;&gt;&lt;!-- s9ymdb:169 --&gt;&lt;img width=&quot;71&quot; height=&quot;110&quot; src=&quot;http://blog.proculo.de/uploads/Messages_WithKeyboard.serendipityThumb.png&quot; alt=&quot;&quot;  /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;Keyboard displayed. The toolbar moves up, attached to the keyboard.&lt;/div&gt;&lt;/div&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
Although my first instinct was to simply use an implicit animation using &lt;code&gt;&lt;a href=&quot;http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html&quot;&gt;UIView&lt;/a&gt;&lt;/code&gt;&#039;s &lt;code&gt;&lt;a href=&quot;http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/beginAnimations:context:&quot;&gt;+beginAnimations:context:&lt;/a&gt;&lt;/code&gt; method, I decided to quickly search the web for some information on how other developers approached this problem.&lt;br /&gt;
&lt;br /&gt;
The results were a little surprising, possibly because the proper way to do it wasn&#039;t as easily available before iPhone OS 3.0 - various people on different message boards and mailing lists suggested a hack that involved looping through all instances of &lt;code&gt;&lt;a href=&quot;http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html&quot;&gt;UIWindow&lt;/a&gt;&lt;/code&gt; to find the one containing an instance of &lt;code&gt;UIKeyboard&lt;/code&gt;, a private class that isn&#039;t even documented in the iPhone SDK. Those hacks then proceeded to modify the dimensions of the view that contains the keyboard and adding the &lt;code&gt;&lt;a href=&quot;http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIToolbar_Class/Reference/Reference.html&quot;&gt;UIToolbar&lt;/a&gt;&lt;/code&gt; instance as a subview, so it would animate into the key window right along with the keyboard.&lt;br /&gt;
&lt;br /&gt;
Needless to say, these hacks are not exactly future-proof or what I would consider a proper implementation of this feature. The &lt;a href=&quot;http://en.wikipedia.org/wiki/Core_Animation&quot;&gt;Core Animation&lt;/a&gt; route was the one to go, so I proceeded in that direction.&lt;br /&gt;
&lt;br /&gt;
More about this after the jump. &lt;br /&gt;&lt;a href=&quot;http://blog.proculo.de/archives/178-Attaching-a-UIToolbar-to-the-iPhones-Keyboard.html#extended&quot;&gt;Continue reading &quot;Attaching a UIToolbar to the iPhone&#039;s Keyboard&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Tue, 06 Oct 2009 20:30:54 +0200</pubDate>
    <guid isPermaLink="false">http://blog.proculo.de/archives/178-guid.html</guid>
    
</item>
<item>
    <title>Asynchronous Networking Using NSOperation And Delegates</title>
    <link>http://blog.proculo.de/archives/175-Asynchronous-Networking-Using-NSOperation-And-Delegates.html</link>
            <category>Tutorials</category>
    
    <comments>http://blog.proculo.de/archives/175-Asynchronous-Networking-Using-NSOperation-And-Delegates.html#comments</comments>
    <wfw:comment>http://blog.proculo.de/wfwcomment.php?cid=175</wfw:comment>

    <slash:comments>6</slash:comments>
    <wfw:commentRss>http://blog.proculo.de/rss.php?version=2.0&amp;type=comments&amp;cid=175</wfw:commentRss>
    

    <author>alexander.repty@mac.com (Alexander Repty)</author>
    <content:encoded>
    Lately, I have been using a lot of REST APIs for various projects that I have been working on. One development pattern that I have constantly used among all these projects is that of using various &lt;code&gt;&lt;a href=&quot;http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/NSOperation_class/Reference/Reference.html&quot;&gt;NSOperation&lt;/a&gt;&lt;/code&gt; objects, feed them to an &lt;code&gt;&lt;a href=&quot;http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html&quot;&gt;NSOperationQueue&lt;/a&gt;&lt;/code&gt; and get the results fed back to the caller via &lt;a href=&quot;http://www.stepwise.com/Articles/Technical/2000-03-03.01.html&quot;&gt;delegation&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Why Would You Do This?&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Now, why would you go through the trouble of learning all these APIs, creating a delegate protocol and implementing all this stuff if you could use a simple &lt;code&gt;initWithContentsOfURL:&lt;/code&gt; (or similar)? The main reason here is asynchronous networking. If you&#039;re going to just fetch network data, such as strings, images or whole XML documents from remote servers, you are going to see some latency, especially if you&#039;re developing for the iPhone and running on an EDGE or 3G network.&lt;br /&gt;
&lt;br /&gt;
If you were to use synchronous networking from within your main thread, you would be blocking your application&#039;s UI until your method stack returns and the system can redraw your views. If you&#039;re looking at multiple seconds of latency, which might easily occur if you&#039;re fetching dynamically generated data from a server, this practically makes your application unusable. The solution to this problem is to push networking tasks into separate functions and move those to different threads.&lt;br /&gt;
&lt;br /&gt;
&lt;a  class=&#039;serendipity_image_link&#039;  rel=&#039;lightbox&#039; href=&#039;http://blog.proculo.de/uploads/Bildschirmfoto2009-09-29um00.29.53.png&#039;&gt;&lt;!-- s9ymdb:164 --&gt;&lt;img width=&quot;110&quot; height=&quot;79&quot; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://blog.proculo.de/uploads/Bildschirmfoto2009-09-29um00.29.53.serendipityThumb.png&quot; alt=&quot;&quot;  /&gt;&lt;br /&gt;Asynchronous networking keeps the main thread available for drawing and other tasks.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Clean Thread Management&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Of course, you could just detach new thread selectors all over your controller, but that would be rather ugly, error-prone and a bitch to maintain. Fortunately, Apple introduced &lt;code&gt;NSOperation&lt;/code&gt; and &lt;code&gt;NSOperationQueue&lt;/code&gt; a while back (in Mac OS X 10.5 Leopard).&lt;br /&gt;
&lt;br /&gt;
For your projects, you will create a subclass of &lt;code&gt;NSOperation&lt;/code&gt; and override the &lt;code&gt;-main&lt;/code&gt; method to do your bidding. This is where the heavy lifting should take place and all your network latency will not matter anymore. I have written a sample application that uses an &lt;code&gt;NSOperation&lt;/code&gt; subclass to fetch an image via HTTP and return it to the controller using a delegate protocol that I have written specifically for this task. My &lt;code&gt;-main&lt;/code&gt; method look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
- (void)main {&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;NSImage *image = nil;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;NSError *error = nil;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;NS_DURING&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;if ([self isCancelled]) {&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;NS_VOIDRETURN;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;NSData *data = [NSData dataWithContentsOfURL:_url options:NSDataReadingUncached error:&amp;error];&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;if (nil != error) {&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;[(NSObject *)_delegate performSelectorOnMainThread:@selector(errorOccurred:) withObject:error waitUntilDone:NO];&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;NS_VOIDRETURN;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;}&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;image = [[NSImage alloc] initWithData:data];&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;NS_HANDLER&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;NS_ENDHANDLER&lt;br /&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;sleep(2); // for illustration purposes&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;[(NSObject *)_delegate performSelectorOnMainThread:@selector(didReceiveImage:) withObject:image waitUntilDone:NO];&lt;br /&gt;
}&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
This method does nothing more than what you would previously have done to retrieve an image given a URL (&lt;code&gt;_url&lt;/code&gt; and &lt;code&gt;_delegate&lt;/code&gt; are instance variables that were filled during initialization). The delegate implements the selectors defined in my protocol, &lt;code&gt;errorOccurred:&lt;/code&gt; and &lt;code&gt;didReceiveImage:&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
So much for the heavy lifting. But how do you actually get this method to run in the first place? This is easy, thanks to &lt;code&gt;NSOperationQueue&lt;/code&gt;, which provides a method to queue &lt;code&gt;NSOperation&lt;/code&gt; subclasses for execution. In my application controller&#039;s &lt;code&gt;-awakeFromNib&lt;/code&gt; method, I instantiate my &lt;code&gt;NSOperation&lt;/code&gt; subclass and add it to the &lt;code&gt;NSOperationQueue&lt;/code&gt; like this:&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
- (void)awakeFromNib {&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;[_progressIndicator startAnimation:self];&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;NSURL *url = [NSURL URLWithString:@&quot;http://alexrepty.com/other/kiwi.jpg&quot;];&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;ImageFetchOperation *operation = [[[ImageFetchOperation alloc] initWithURL:url delegate:self] autorelease];&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;[_queue addOperation:operation];&lt;br /&gt;
}&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Add the implementation of the delegate protocol and you&#039;re done! What you end up with is a nice, clean and efficient way of dealing with networking that helps to keep your code readable, error-free and makes for a better user experience by keeping the main thread free of blocking operations.&lt;br /&gt;
&lt;br /&gt;
&lt;a  class=&#039;serendipity_image_link&#039;  rel=&#039;lightbox&#039; href=&#039;http://blog.proculo.de/uploads/Bildschirmfoto2009-09-29um00.30.07.png&#039;&gt;&lt;!-- s9ymdb:165 --&gt;&lt;img width=&quot;110&quot; height=&quot;89&quot; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://blog.proculo.de/uploads/Bildschirmfoto2009-09-29um00.30.07.serendipityThumb.png&quot; alt=&quot;Isn&#039;t Kiwi cute?&quot; /&gt;&lt;br /&gt;Delegation makes sure your application controller has immediate access to the image once it has been fetched.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Yes, the cat in the picture is mine. :)&lt;br /&gt;
&lt;br /&gt;
Feel free to &lt;a href=&quot;http://alexrepty.com/other/ImageFetcher.zip&quot;&gt;download the source code&lt;/a&gt; for this example and use it in your own projects. If you have any comments or questions, use the box below or &lt;a href=&quot;http://twitter.com/arepty&quot;&gt;ask me on Twitter&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Update&lt;/strong&gt;: I&#039;ve published the source code for this tutorial on &lt;a href=&quot;http://github.com/&quot;&gt;Github&lt;/a&gt;:&lt;br /&gt;
&lt;a href=&quot;http://github.com/alexrepty/Asynchronous-Image-Fetcher/fast_forward&quot;&gt;http://github.com/alexrepty/Asynchronous-Image-Fetcher/fast_forward&lt;/a&gt;&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Mon, 28 Sep 2009 23:41:48 +0200</pubDate>
    <guid isPermaLink="false">http://blog.proculo.de/archives/175-guid.html</guid>
    
</item>

</channel>
</rss>
