<?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>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>7</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>