<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Emmer Inc &#187; Cocoa Touch</title>
	<atom:link href="http://blog.emmerinc.be/index.php/category/cocoa-touch/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.emmerinc.be</link>
	<description>Tales from a .NET developer who's making the jump to the iPhone &#38; App Store wonderland.</description>
	<lastBuildDate>Wed, 23 Jun 2010 20:57:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Converting NSData to NSString and vice versa</title>
		<link>http://blog.emmerinc.be/index.php/2010/06/23/converting-nsdata-to-nsstring-and-vice-versa/</link>
		<comments>http://blog.emmerinc.be/index.php/2010/06/23/converting-nsdata-to-nsstring-and-vice-versa/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 20:40:19 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[NSData]]></category>
		<category><![CDATA[NSString]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=767</guid>
		<description><![CDATA[Since I always forget how to convert a NSData object to NSString and vice versa, I thought I&#8217;d write it down as a reference. Every time I work with a REST service and need to know what response I&#8217;m receiving, before handing the NSData object to a NSXMLParser, I&#8217;m always dumbfounded that I&#8217;ve forgotten how [...]]]></description>
			<content:encoded><![CDATA[<p>Since I always forget how to convert a NSData object to NSString and vice versa, I thought I&#8217;d write it down as a reference. Every time I work with a REST service and need to know what response I&#8217;m receiving, before handing the NSData object to a NSXMLParser, I&#8217;m always dumbfounded that I&#8217;ve forgotten how to do the conversion.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// From NSString to NSData</span>
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Some string&quot;</span>;
<span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>data <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>text dataUsingEncoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// From NSData to NSString</span>
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> alloc<span style="color: #002200;">&#93;</span> initWithData<span style="color: #002200;">:</span>data encoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Who knows if it helps some one else.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2010/06/23/converting-nsdata-to-nsstring-and-vice-versa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping your UITableViewController clean</title>
		<link>http://blog.emmerinc.be/index.php/2010/04/03/keeping-your-uitableviewcontroller-clean/</link>
		<comments>http://blog.emmerinc.be/index.php/2010/04/03/keeping-your-uitableviewcontroller-clean/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 19:01:27 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[UITableView]]></category>
		<category><![CDATA[UITableViewController]]></category>
		<category><![CDATA[YCSectionController]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=677</guid>
		<description><![CDATA[We&#8217;ve all done it, admit it, we&#8217;ve all written enormous if structures in the datasource/delegate methods of a table. It got the job done, but ever needed to change the order of the sections or needed to add/remove some rows? Things get out of hand very easily when the appearance and behavior of rows is [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve all done it, admit it, we&#8217;ve all written enormous if structures in the datasource/delegate methods of a table. It got the job done, but ever needed to change the order of the sections or needed to add/remove some rows? Things get out of hand very easily when the appearance and behavior of rows is varying. Indeed, these if structures are horrible maintenance-wise. Granted, tutorials often focus on showing some specific functionality and leave the refactoring to the reader, so aspiring iPhone developers often don&#8217;t know any better.</p>
<p>Here&#8217;s a way to keep your UITableViewController (or any other view controller or class your using as datasource or delegate) clean, this approach is aimed at tables with multiple sections. Tables with 1 section have limited benefit of using this approach although extra sections could be easily added later. The key is to move all the logic for a specific section in a table to its own class, which is responsible for his own rows and nothing more.</p>
<p>To achieve this we create a protocol called YCSectionController:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@protocol</span> YCSectionController
&nbsp;
@required
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>table numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath;
&nbsp;
@optional
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView titleForHeaderInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView titleForFooterInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>This protocol will be used to specify to which methods a custom section controller must conform. Each custom section controller has knowledge about the amount of rows &#038; how to display each row, these are the required methods. Extra methods can be added like what to do when a row is selected for instance. Depending on the appearance of the section &#038; the desired behavior each custom section controller class implements the necessary methods.</p>
<p>The YCHeaderSectionController implementation below shows a minimal implementation.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@implementation</span> YCHeaderSectionController
&nbsp;
<span style="color: #6e371a;">#pragma mark YCSectionController methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>table numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #2400d9;">1</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>cellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;HeaderCell&quot;</span>;
&nbsp;
	UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UITableViewCell<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>cellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithStyle<span style="color: #002200;">:</span>UITableViewCellStyleDefault reuseIdentifier<span style="color: #002200;">:</span>cellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
		cell.accessoryType <span style="color: #002200;">=</span> UITableViewCellAccessoryDisclosureIndicator;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>indexPath.row <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		cell.textLabel.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Yannick Compernol&quot;</span>;
&nbsp;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>indexPath.row <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		url <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://yannick.compernol.be&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>url<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> openURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView titleForHeaderInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Info&quot;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>One you&#8217;ve made several custom section controllers all you have to is to hook them up in your UITableViewController and dispatch the datasource/delegate methods to the custom section controllers. Note the UITableViewControllers has an array which will hold all the custom section controllers, the array is filled in the ViewDidLoad: method.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> MainTableViewController <span style="color: #002200;">:</span> UITableViewController <span style="color: #002200;">&#123;</span>
	<span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>sectionControllers;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> MainTableViewController
&nbsp;
...
&nbsp;
<span style="color: #6e371a;">#pragma mark UIViewController methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>viewDidLoad <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>super viewDidLoad<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #a61390;">id</span> header <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>YCHeaderSectionController alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">id</span> content <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>YCContentSectionController alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">id</span> footer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>YCFooterSectionController alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
	sectionControllers <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> alloc<span style="color: #002200;">&#93;</span> initWithObjects<span style="color: #002200;">:</span>header, content, footer, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>header release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>content release<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>footer release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
...
&nbsp;
<span style="color: #6e371a;">#pragma mark UITableViewDataSource methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>numberOfSectionsInTableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>sectionControllers count<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>table numberOfRowsInSection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSInteger<span style="color: #002200;">&#41;</span>section <span style="color: #002200;">&#123;</span>
	id&lt;YCSectionController&gt; sectionController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>sectionControllers objectAtIndex<span style="color: #002200;">:</span>section<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>sectionController tableView<span style="color: #002200;">:</span>table numberOfRowsInSection<span style="color: #002200;">:</span>section<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
	id&lt;YCSectionController&gt; sectionController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>sectionControllers objectAtIndex<span style="color: #002200;">:</span>indexPath.section<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>sectionController tableView<span style="color: #002200;">:</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span>indexPath<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
...
&nbsp;
<span style="color: #6e371a;">#pragma mark UITableViewDelegate methods</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
	id&lt;YCSectionController&gt; sectionController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>sectionControllers objectAtIndex<span style="color: #002200;">:</span>indexPath.section<span style="color: #002200;">&#93;</span>;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>sectionController respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>tableView<span style="color: #002200;">:</span>didSelectRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>sectionController tableView<span style="color: #002200;">:</span>tableView didSelectRowAtIndexPath<span style="color: #002200;">:</span>indexPath<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>	
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>And that is about it, it can be taken further than I showed here, but I think this is a decent starter. The bottom line is that the UITableViewController has less code and the specific code (appearance &#038; behavior) for each section is contained in its own class. Adding to the maintainability of the whole table.</p>
<p><a href="http://blog.emmerinc.be/wp-content/uploads/2010/04/CleanTablesSample.png"><img src="http://blog.emmerinc.be/wp-content/uploads/2010/04/CleanTablesSample.png" alt="" title="Clean Tables Sample" width="320" height="480" class="aligncenter size-full wp-image-686" /></a></p>
<p>A running example (screenshot shown above) can be downloaded <a href='http://blog.emmerinc.be/wp-content/uploads/2010/04/CleanTableViewControllers.zip'>here</a>.  </p>
<p>There&#8217;s only one thing I&#8217;m still struggling with, since id<YCSectionController> does not have a respondsToSelector: method, you&#8217;ll get a warning that respondsToSelector: wasn&#8217;t found in the protocol. An easy fix would be to add it to the protocol, but that doesn&#8217;t feel right as it&#8217;s not part of the behavior I wanted to encapsulate in the section controller. I&#8217;d love to hear your thoughts/comments on this!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2010/04/03/keeping-your-uitableviewcontroller-clean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiline cells in iPhone SDK 3.0</title>
		<link>http://blog.emmerinc.be/index.php/2009/06/21/multiline-cells-in-iphone-sdk-3-0/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/06/21/multiline-cells-in-iphone-sdk-3-0/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 13:46:21 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[iPhone SDK 3.0]]></category>
		<category><![CDATA[UITableViewCell]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=520</guid>
		<description><![CDATA[While surfing the web and browsing through development related forums, I encountered a lot of questions regarding multiline UITableViewCells. Prior to iPhone SDK 3.0 this was not an easy feat and although it is very common in UIs, the work that is related to creating multiline cells is not  proportional to how common they [...]]]></description>
			<content:encoded><![CDATA[<p>While surfing the web and browsing through development related forums, I encountered a lot of questions regarding multiline UITableViewCells. Prior to iPhone SDK 3.0 this was not an easy feat and although it is very common in UIs, the work that is related to creating multiline cells is not  proportional to how common they are.</p>
<p>Apple definitely made it easier with new SDK, since we can interact directly with the UILabel. I know it&#8217;s pretty straightforward, but I&#8217;m always surprised by how many developers disregard the <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html">documentation</a> &#038; turn to forums/blogs for help.</p>
<p>Creating multiline cells is now as simple as setting the numberOfLines property to 0 (or a predefined number) of the textLabel, which is in turn a property of the cell. Given the height of the cell is sufficient, behold a multiline cell.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">cell.textLabel.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Some long text...&quot;</span>;
cell.textLabel.numberOfLines <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;</pre></div></div>

<p>Change the height of the cell with the tableView:heightForRowAtIndexPath: delegate method of the UITableViewController, either by returning a fixed height or by calculating the height needed to show the desired text.</p>
<p>Note that the text property of a cell is being deprecated in favor of textLabel.text, more info on the new 3.0 predefined cell styles can be found <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/c/tdef/UITableViewCellStyle">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/06/21/multiline-cells-in-iphone-sdk-3-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Load view from nib improvement</title>
		<link>http://blog.emmerinc.be/index.php/2009/05/11/load-view-from-nib-improvement/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/05/11/load-view-from-nib-improvement/#comments</comments>
		<pubDate>Mon, 11 May 2009 18:56:13 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[nib]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=482</guid>
		<description><![CDATA[One of the constants in a developer&#8217;s life is seeing code and knowing you&#8217;re doing it wrong, but not really knowing how to fix it and get it right. Due to whatever reason: no time&#8230; My Facebook like loading indicator article was no exception, the way I loaded a specific view from a separate nib [...]]]></description>
			<content:encoded><![CDATA[<p>One of the constants in a developer&#8217;s life is seeing code and knowing you&#8217;re doing it wrong, but not really knowing how to fix it and get it right. Due to whatever reason: no time&#8230; My <a href="http://blog.emmerinc.be/index.php/2009/04/25/facebook-like-loading-indicator/">Facebook like loading indicator</a> article was no exception, the way I loaded a specific view from a separate nib felt so bad. Yet I posted it since holding it back for another 4 weeks was no option either. A week ago I had a eureka moment and it all made sense at around 2am on a Saterday morning. Here&#8217;s the correct method to load a view from a separate nib file.</p>
<p>Instead of looping through the contents of the nib, the key are IBOutlets. Create a NSView IBOutlet in your controller class were you&#8217;ll want to use the view. Next step is to open your nib file which contains your external view and change the File Owner&#8217;s class identity to the controller class you&#8217;ve just extended with the IBOutlet for the view. Now just ctrl-drag from the File Owner to your view and select your desired IBOutlet from the list.</p>
<p>Now you&#8217;ve connected your controller and the external view, yet the IBOutlet will not be hooked up automatically when your controller&#8217;s created. This is a good thing because we can postpone loading the extra nib to when it&#8217;s really necessary saving resources for other, more important stuff. This is a practice Apple encourages, using multiple nib files and loading them dynamically when needed.</p>
<p>This is the code needed to load the nib, it&#8217;ll automaticall hook up your controller&#8217;s IBOutlet to your view.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> loadNibNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;YourNibName&quot;</span> owner<span style="color: #002200;">:</span>self options<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Simple? Indeed, yet it took me a while to realize using an external nib is basically just the same as putting all your views in a single nib container. It&#8217;s all based on hooking up IBOutlets.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/05/11/load-view-from-nib-improvement/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Facebook like loading indicator</title>
		<link>http://blog.emmerinc.be/index.php/2009/04/25/facebook-like-loading-indicator/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/04/25/facebook-like-loading-indicator/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 10:54:55 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[threading]]></category>
		<category><![CDATA[UIActivityIndicator]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=219</guid>
		<description><![CDATA[When performing an action that may take some time, it&#8217;s advised to show something to signal that the operation is being performed &#38; the application is not crashing. Here&#8217;s an example on how to accomplish a loading indicator as used in the iPhone Facebook application.

First we&#8217;ll create the actual loading view, let&#8217;s add an empty [...]]]></description>
			<content:encoded><![CDATA[<p>When performing an action that may take some time, it&#8217;s advised to show something to signal that the operation is being performed &amp; the application is not crashing. Here&#8217;s an example on how to accomplish a loading indicator as used in the iPhone Facebook application.</p>
<p><img class="alignright size-full wp-image-330" title="Loading View" src="http://blog.emmerinc.be/wp-content/uploads/2009/03/loadingview.png" alt="Loading View" width="190" height="102" /></p>
<p>First we&#8217;ll create the actual loading view, let&#8217;s add an empty XIB to our Xcode project called LoadingView. Add a UIView to the nib and drag a UIImageView onto it. Use a vector program like <a title="Inkscape" href="http://www.inkscape.org/">Inkscape</a> to create a black rectangle with rounded corners. Use a UILabel and a UIActivityIndicator to create something like the screenshot to the right. Be sure to check the animating property of the activity indicator and change the alpha of the root view to 0.8 for intance, since we want the view to be slightly transparant.</p>
<p>Once we&#8217;ve made the actual view, it&#8217;s time to show it.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span>UIView<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>newLoadingView <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>nib <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> loadNibNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;LoadingView&quot;</span> owner<span style="color: #002200;">:</span>self options<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
   <span style="color: #400080;">NSEnumerator</span> <span style="color: #002200;">*</span>enumerator <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>nib objectEnumerator<span style="color: #002200;">&#93;</span>;
   <span style="color: #a61390;">id</span> object;
&nbsp;
   <span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>object <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>enumerator nextObject<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
      <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>object isMemberOfClass<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIView class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
         <span style="color: #a61390;">return</span> object;
      <span style="color: #002200;">&#125;</span>
   <span style="color: #002200;">&#125;</span>
&nbsp;
   <span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>doWork <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSAutoreleasePool</span> <span style="color: #002200;">*</span>pool <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSAutoreleasePool</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
   <span style="color: #11740a; font-style: italic;">// Add lenghty operation.</span>
&nbsp;
   <span style="color: #002200;">&#91;</span>loadingView removeFromSuperview<span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>pool release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>someMethod <span style="color: #002200;">&#123;</span>
   loadingView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self newLoadingView<span style="color: #002200;">&#93;</span>;
   loadingView.center <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">350</span><span style="color: #002200;">&#41;</span>;
   <span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>loadingView<span style="color: #002200;">&#93;</span>;
&nbsp;
   <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> detachNewThreadSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>doWork<span style="color: #002200;">&#41;</span> toTarget<span style="color: #002200;">:</span>self withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> <span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>We&#8217;re using the newLoadingView: method to retrieve the view from the nib, the reason we&#8217;re looping through the contents of the nib is one cannot garantee the order in which items are retrieved will always be the same. For instance the index of the loading view will be different in firmware version 2.0 and 2.1. We retrieve a UIView item, in this case the loading view, since it&#8217;s the only UIView in the nib. I&#8217;m sure this code could be improved though, using your own derived UIView and checking for this derived class would be better. The center property of the loading view can be used to position the view, the top left corner has coordinates 0,0. (If anyone has a better method of getting a specific view from a nib, do tell)</p>
<p>The someMethod method is the one to call to start everything, this method will show the actual loading view and start the doWork method on a seperate thread. The reason we&#8217;re using a seperate thread is not to lock up the interface, otherwise the interface would freeze while the lenghty operation would be performed. The doWork method hides the loading view once everything is done.</p>
<p><strong>Extension:</strong> The above code has one disadvantage, when using a tab controller the loading view will disappear once another tab is selected, returning to the original tab will show the loading view again though. In some cases this behaviour isn&#8217;t wanted, how do we solve this? Instead of showing the loading view on top of the content view displayed by the tab controller, we&#8217;ll show it on top of all the views, on top of the tab controller.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// Show loading view on top of everything</span>
<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span>.keyWindow addSubview<span style="color: #002200;">:</span>loadingView<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>And that&#8217;s all there is to it.</p>
<p><strong>Update</strong>: <a href="http://blog.emmerinc.be/index.php/2009/05/11/load-view-from-nib-improvement/">here</a>&#8217;s the correct method to load a view from a separate nib file.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/04/25/facebook-like-loading-indicator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New line in UILabel and UITextView</title>
		<link>http://blog.emmerinc.be/index.php/2009/03/23/new-line-in-uilabel-and-uitextview/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/03/23/new-line-in-uilabel-and-uitextview/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 22:05:58 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[UILabel]]></category>
		<category><![CDATA[UITextView]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=312</guid>
		<description><![CDATA[Somehow I never figured out how to insert a new line in a UILabel or UITextView, up until now. A new line is added with Alt + Enter. Using Enter only while editing the text will result in a new line in editing mode, but the new line is lost when editing mode is quit.
There [...]]]></description>
			<content:encoded><![CDATA[<p>Somehow I never figured out how to insert a new line in a UILabel or UITextView, up until now. A new line is added with Alt + Enter. Using Enter only while editing the text will result in a new line in editing mode, but the new line is lost when editing mode is quit.</p>
<p>There you have it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/03/23/new-line-in-uilabel-and-uitextview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple async NSURLConnections example</title>
		<link>http://blog.emmerinc.be/index.php/2009/03/15/multiple-async-nsurlconnections-example/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/03/15/multiple-async-nsurlconnections-example/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 23:23:17 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[NSURLConnection]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=187</guid>
		<description><![CDATA[After posting the custom NSURLConnection subclass blog post, I thought I might post an example of how it would be used, since quite a lot of visitors came to the blog searching for the keywords: &#8220;multiple asynchronous NSURLConnection&#8221;. The code itself is pretty straightforward, but might prove handy for those developers setting their first steps [...]]]></description>
			<content:encoded><![CDATA[<p>After posting the custom NSURLConnection subclass <a href="http://blog.emmerinc.be/index.php/2009/03/02/custom-nsurlconnection-class-with-tag/">blog post</a>, I thought I might post an example of how it would be used, since quite a lot of visitors came to the blog searching for the keywords: &#8220;multiple asynchronous NSURLConnection&#8221;. The code itself is pretty straightforward, but might prove handy for those developers setting their first steps in Cocoa Touch.</p>
<p>The basic idea is to use a dictionary which stores the received data per tag, remember that the actual connection cannot be used as the key of a dictionary. Each NSURLConnection methods retrieve the NSMutableData object from the dictionary based on the tag and does it magic with it.</p>
<p>If you don&#8217;t know how to use the NSURLConnection class, take a look at the <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html">documentation</a>. That should get you going in no time.</p>
<p>First of all add a mutable dictionary to the header file:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSMutableDictionary</span> <span style="color: #002200;">*</span>receivedData;</pre></div></div>

<p>Here&#8217;s the actual code. The load method starts the actual asynchronous calls. The startAsyncLoad:tag and dataForConnection methods are convenience methods to keep the code tidy &amp; readable.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>startAsyncLoad<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURL</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>url tag<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tag <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSMutableURLRequest</span> <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableURLRequest</span> requestWithURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span>;
   CustomURLConnection <span style="color: #002200;">*</span>connection <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CustomURLConnection alloc<span style="color: #002200;">&#93;</span> initWithRequest<span style="color: #002200;">:</span>request delegate<span style="color: #002200;">:</span>self startImmediately<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span> tag<span style="color: #002200;">:</span>tag<span style="color: #002200;">&#93;</span>;
&nbsp;
   <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>connection<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
      <span style="color: #002200;">&#91;</span>receivedData setObject<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableData</span> data<span style="color: #002200;">&#93;</span> retain<span style="color: #002200;">&#93;</span> forKey<span style="color: #002200;">:</span>connection.tag<span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSMutableData</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>dataForConnection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CustomURLConnection<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSMutableData</span> <span style="color: #002200;">*</span>data <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>receivedData objectForKey<span style="color: #002200;">:</span>connection.tag<span style="color: #002200;">&#93;</span>;
   <span style="color: #a61390;">return</span> data;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>load <span style="color: #002200;">&#123;</span>
   receivedData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableDictionary</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
   <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url1 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://blog.emmerinc.be&quot;</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://www.emmerinc.be&quot;</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url3 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://twitter.com/emmerinc&quot;</span><span style="color: #002200;">&#93;</span>; 
&nbsp;
   <span style="color: #002200;">&#91;</span>self startAsyncLoad<span style="color: #002200;">:</span>url1 tag<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;tag1&quot;</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>self startAsyncLoad<span style="color: #002200;">:</span>url2 tag<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;tag2&quot;</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>self startAsyncLoad<span style="color: #002200;">:</span>url3 tag<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;tag3&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection didReceiveResponse<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLResponse</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>response <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSMutableData</span> <span style="color: #002200;">*</span>dataForConnection <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self dataForConnection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CustomURLConnection<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>dataForConnection setLength<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection didReceiveData<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>data <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSMutableData</span> <span style="color: #002200;">*</span>dataForConnection <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self dataForConnection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CustomURLConnection<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>dataForConnection appendData<span style="color: #002200;">:</span>data<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connectionDidFinishLoading<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSMutableData</span> <span style="color: #002200;">*</span>dataForConnection <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self dataForConnection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CustomURLConnection<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>connection release<span style="color: #002200;">&#93;</span>;
&nbsp;
   <span style="color: #11740a; font-style: italic;">// Do something with the dataForConnection.</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>In the connectionDidFinishLoading: method the tag of the connection should be used to determine what to do with the actual received data. And that is about it!</p>
<p>Don&#8217;t forget to release the dictionary in the deconstructor or after all the asynchronous calls have been completed though.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/03/15/multiple-async-nsurlconnections-example/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>iPhone (game) development links</title>
		<link>http://blog.emmerinc.be/index.php/2009/03/05/iphone-game-development-links/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/03/05/iphone-game-development-links/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 20:12:53 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[links]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=103</guid>
		<description><![CDATA[A collection of links/blogs I gathered in the course of the last month regarding iPhone (game) development and some other useful things. Probably of the most value to beginning iPhone developers.
Blog: Cocoa with Love
Includes an asteriods style game in CoreAnimation how to.
Blog: CrystalMinds
Includes a Duck Hunt game with regular UIViews how to. 
Documentation: Create a [...]]]></description>
			<content:encoded><![CDATA[<p>A collection of links/blogs I gathered in the course of the last month regarding iPhone (game) development and some other useful things. Probably of the most value to beginning iPhone developers.</p>
<p>Blog: <a href="http://cocoawithlove.com/">Cocoa with Love</a><br />
Includes an asteriods style game in CoreAnimation how to.</p>
<p>Blog: <a href="http://www.crystalminds.net/">CrystalMinds</a><br />
Includes a Duck Hunt game with regular UIViews how to. </p>
<p>Documentation: <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_10.html">Create a singleton instance</a><br />
Apple documentation on how to create a singleton instance.</p>
<p>Code snippets: <a href="http://www.iphoneexamples.com/">iPhone SDK Examples</a><br />
Some simple but useful examples.</p>
<p>Blog: <a href="http://iphonedevelopment.blogspot.com/">iPhone Development</a><br />
Decent blog with some good articles.</p>
<p>Forum: <a href="http://www.iphonedevsdk.com/">iPhone Dev SDK</a><br />
One of the largest forums regarding iPhone (and Mac) development, contains an interesting business sub-forum.</p>
<p>Blog: <a href="http://iphonedevelopertips.com/">iPhone Developer Tips</a><br />
Another active and useful blog.</p>
<p>Blog: <a href="http://iphonedevelopmentbits.com/">iPhone Development Bits</a><br />
Has some nice links to other articles including a little game.</p>
<p>That&#8217;ll be it for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/03/05/iphone-game-development-links/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom NSURLConnection class with tag</title>
		<link>http://blog.emmerinc.be/index.php/2009/03/02/custom-nsurlconnection-class-with-tag/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/03/02/custom-nsurlconnection-class-with-tag/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 21:41:15 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[NSURLConnection]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=85</guid>
		<description><![CDATA[A caveat one quickly encounters when using multiple asynchronous NSURLConnections with the same target delegate is that there is no easy way to distinguish one connection from the other, in for instance the connection:didReceiveData: method.
Since using multiple asynchronous connections implies handling the received data chunks yourself, one is likely to create a dictionary which contains [...]]]></description>
			<content:encoded><![CDATA[<p>A caveat one quickly encounters when using multiple asynchronous <a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html">NSURLConnections</a> with the same target delegate is that there is no easy way to distinguish one connection from the other, in for instance the connection:didReceiveData: method.</p>
<p>Since using multiple asynchronous connections implies handling the received data chunks yourself, one is likely to create a dictionary which contains a NSMutableData object for each NSURLConnection key. Unfortunately does a <a href="http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html">NSDictionary</a> copy its keys and this is not something a NSURLConnection supports. A quick solution to avoid this is to make a subclass with a tag to distinguish each connection. This tag can be used as key in the dictionary.</p>
<p>Interface:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> CustomURLConnection <span style="color: #002200;">:</span> <span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">&#123;</span>
   <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>tag;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>tag;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithRequest<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLRequest</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request delegate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>delegate startImmediately<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>startImmediately tag<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tag;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Implementation:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@implementation</span> CustomURLConnection
&nbsp;
<span style="color: #a61390;">@synthesize</span> tag;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithRequest<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLRequest</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>request delegate<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>delegate startImmediately<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>startImmediately tag<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tag <span style="color: #002200;">&#123;</span>
   self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithRequest<span style="color: #002200;">:</span>request delegate<span style="color: #002200;">:</span>delegate startImmediately<span style="color: #002200;">:</span>startImmediately<span style="color: #002200;">&#93;</span>;
&nbsp;
   <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
      self.tag <span style="color: #002200;">=</span> tag;
   <span style="color: #002200;">&#125;</span>
   <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>dealloc <span style="color: #002200;">&#123;</span>
   <span style="color: #002200;">&#91;</span>tag release<span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>super dealloc<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>As you can see, creating a subclass with a tag property is rather easy and solves the dictionary issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/03/02/custom-nsurlconnection-class-with-tag/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Parsing serialized .NET DateTime to NSDate</title>
		<link>http://blog.emmerinc.be/index.php/2009/02/25/parsing-serialized-net-datetime-to-nsdate/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/02/25/parsing-serialized-net-datetime-to-nsdate/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 21:38:18 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[NSDate]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=22</guid>
		<description><![CDATA[In my application I have to parse a serialized .NET DateTime returned from a REST service to a NSDate object. I expected to be able to use the initWithString: constructor of the NSDate class, but this wasn&#8217;t the case. The initWithString: constructor expects a string with the following format &#8220;2009-02-25 22:00:00 +0100&#8243;, yet the serialized [...]]]></description>
			<content:encoded><![CDATA[<p>In my application I have to parse a serialized .NET DateTime returned from a REST service to a NSDate object. I expected to be able to use the initWithString: constructor of the NSDate class, but this wasn&#8217;t the case. The <a title="NSDate class reference" href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDate/initWithString:">initWithString:</a> constructor expects a string with the following format &#8220;2009-02-25 22:00:00 +0100&#8243;, yet the serialized .NET DateTime is in the following format &#8220;2009-02-25T22:00:00+01:00&#8243;. Notice the &#8220;T&#8221; and the semicolon in the timezone offset.</p>
<p>To solve this difference in format, one could manipulate the actual string to comply to the desired format or one could use the <a title="NSDateFormatter class reference" href="http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html">NSDateFormatter</a> class. The latter being the &#8220;cleanest&#8221; solution.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSDateFormatter</span> <span style="color: #002200;">*</span>formatter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDateFormatter</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>formatter setDateFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;yyyy-MM-dd'T'HH:mm:ssZ&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSDate</span> <span style="color: #002200;">*</span>date <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>formatter dateFromString<span style="color: #002200;">:</span>text<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>The used format patterns comply to the Unicode standard <a title="Unicode Technical Standard #35" href="http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns">UTS #35</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/02/25/parsing-serialized-net-datetime-to-nsdate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
