<?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>Mac / iPhone App Development</title>
	<atom:link href="http://benreeves.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://benreeves.co.uk</link>
	<description>Home of a Small Time Developer</description>
	<lastBuildDate>Wed, 26 May 2010 14:24:12 +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>iPhone Expat XML Parser Wrapper</title>
		<link>http://benreeves.co.uk/iphone-expat-xml-parser-wrapper/</link>
		<comments>http://benreeves.co.uk/iphone-expat-xml-parser-wrapper/#comments</comments>
		<pubDate>Mon, 24 May 2010 14:30:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Atom]]></category>
		<category><![CDATA[Expat]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[NSXMLParser]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://benreeves.co.uk/?p=314</guid>
		<description><![CDATA[Often in iPhone projects I&#8217;ve needed to parse XML documents from the internet.

I want the data to be processed  and shown to the user as quickly as possible.
If the file is large I don&#8217;t want to have to store the entire contents in memory.

Using NSXMLParsers initWithURL: method the xml file is downloaded synchronously with NSURLConnection before parsing. If [...]]]></description>
			<content:encoded><![CDATA[<p>Often in iPhone projects I&#8217;ve needed to parse XML documents from the internet.</p>
<ul>
<li>I want the data to be processed  and shown to the user as quickly as possible.</li>
<li>If the file is large I don&#8217;t want to have to store the entire contents in memory.</li>
</ul>
<p>Using NSXMLParsers initWithURL: method the xml file is downloaded synchronously with NSURLConnection before parsing. If NSXMLParser was able to begin as soon as stream buffer began to fill, even though the overall parsing time wouldn&#8217;t be reduced significantly if the updates are immediately displayed the user perceived time decreases significantly.</p>
<p>Using the excellent <a href="http://www.robbiehanson.com/expat.html">objective c expat wrapper</a> library by <a href="http://www.robbiehanson.com/">Robbie Hanson</a> as a base iPhoneExpat uses CFNetwork &amp; CFHTTPMessage to create and feed a http stream gradually into Expat. If the server supports gzip compression <a href="http://www.zlib.net/">zlib</a> is used to decompress the stream on fly.</p>
<p>iPhone Expat offer 3 methods for initialization</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;">id</span><span style="color: #002200;">&#41;</span>initWithContentsOfURL<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;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithContentsOfFile<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>path;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithData<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;</pre></div></div>

<p>The delegate messages are also a drop in replacement for NSXMLParser</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@protocol</span> ExpatXMLParserDelegate 
&nbsp;
@optional
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parserDidStartDocument<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parserDidEndDocument<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser didStartMappingPrefix<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>prefix toURI<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>namespaceURI;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser didEndMappingPrefix<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>prefix;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser foundComment<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>comment;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser foundProcessingInstructionWithTarget<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>target data<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>data;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser parseErrorOccurred<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parseError;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser shouldProcessAttributesForElement<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>elementName;
&nbsp;
@required
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser didStartElement<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>elementName namespaceURI<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>namespaceURI qualifiedName<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>qualifiedName attributes<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>attributeDict;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser didEndElement<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>elementName namespaceURI<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>namespaceURI qualifiedName<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>qName;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser foundCharacters<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><span style="color: #a61390;">string</span>;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>However</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>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>ExpatXMLParser <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser foundCharacters<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><span style="color: #a61390;">string</span>;</pre></div></div>

<p>Will report the entire contents of a tag so you don&#8217;t need an NSMutablestring to buffer fragments in your delegate. e.g.</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>parser<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSXMLParser</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parser foundCharacters<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><span style="color: #a61390;">string</span>
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>buffer release<span style="color: #002200;">&#93;</span>;
	buffer <span style="color: #002200;">=</span> <span style="color: #a61390;">string</span>;
	<span style="color: #002200;">&#91;</span>buffer retain<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Should be good in 99% of cases to get the entire contents of a tag</p>
<p><strong>The project can be found here</strong></p>
<p><a href="http://github.com/zootreeves/iPhoneExpat">http://github.com/zootreeves/iPhoneExpat</a></p>
<p>Alternatively checkout the code using git: http://github.com/zootreeves/iPhoneExpat</p>
<p><strong>Benchmark test output:</strong></p>
<p><strong><span style="font-weight: normal;">I&#8217;ve included a test application which sequentially downloads and parses the following feeds:</span></strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topalbums/sf=143441/limit=300/explicit=true/xml&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topalbums/sf=143441/limit=300/explicit=true/xml&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://feeds.feedburner.com/DilbertDailyStrip&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://designsponge.blogspot.com/atom.xml&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://www.slate.com/rss/&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://rssfeeds.usatoday.com/UsatodaycomBooks-TopStories&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://googleblog.blogspot.com/atom.xml&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;hhttp://api.flickr.com/services/feeds/groups_pool.gne?id=61057342@N00〈=en-us&amp;amp;format=rss_200&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://phobos.apple.com/WebObjects/MZStore.woa/wpa/MRSS/topsongs/limit=25/rss.xml&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://www.readwriteweb.com/rss.xml&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://rssfeeds.usatoday.com/UsatodaycomNation-TopStories&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://dictionary.reference.com/wordoftheday/wotd.rss&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://www.quotationspage.com/data/qotd.rss&quot;</span>,
<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://sports.espn.go.com/espn/rss/news&quot;</span></pre></div></div>

<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">Time to reach the first element Expat: 8.611217 &#8212; NSXMLParser: 15.404100<br />
Total time for Expat: 10.902272 &#8212; NSXMLParser: 17.108309</p>
<p>Memory is also reduced by a factor of about x4 (see screenshots)<br />

<a href='http://benreeves.co.uk/iphone-expat-xml-parser-wrapper/screen-shot-2010-05-24-at-15-37-29/' title='NSXMLParser memory usage'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-24-at-15.37.29-150x150.png" class="attachment-thumbnail" alt="" title="NSXMLParser memory usage" /></a>
<a href='http://benreeves.co.uk/iphone-expat-xml-parser-wrapper/screen-shot-2010-05-24-at-15-42-40/' title='Screen shot 2010-05-24 at 15.42.40'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-24-at-15.42.40-150x150.png" class="attachment-thumbnail" alt="" title="Screen shot 2010-05-24 at 15.42.40" /></a>
</p>
<p><strong>Further Considerations</strong></p>
<ul>
<li>It would be great if http requests were persistent, however after setting kCFStreamPropertyHTTPAttemptPersistentConnection to true using <a href="http://www.tuffcode.com/">httpscoop</a> I will still able to intercept &#8220;connection close&#8221; messages between requests to the same server. I think I must be doing something wrong here.</li>
<li>It would be preferable if as many objects as possible were released manually rather than using an autorelease pool. For example the delegate methods that pass an elementName it is common for the client to use this string to determine their current tag, but rare that they actually want to retain it. The code could be altered so these strings are not placed in a pool and are released immediately after the delegate message is sent. Not only can the overhead of collection be avoided but CFStringCreateWithCharactersNoCopy can be used as well.</li>
<li>With UTF8 creating CFStrings with the [NSString stringwithutf8string:] was no problem. However when I configured Expat to use UTF-16 characters internally I found that CFStringCreateWithCharacters would often return garbage. The problem is I was passing in UINT16_MAX as the buffer length hoping that the CFString would be terminated at null, however it doesn&#8217;t work that way and I had to change everything to calculate the buffer size using UniCharStrlen(buffer) before hand.</li>
<li> FTP (CFFTPStream) and file streams could easily be supported.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/iphone-expat-xml-parser-wrapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JCJ Locums app</title>
		<link>http://benreeves.co.uk/jcj-locums-app/</link>
		<comments>http://benreeves.co.uk/jcj-locums-app/#comments</comments>
		<pubDate>Sat, 08 May 2010 13:27:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://benreeves.co.uk/?p=299</guid>
		<description><![CDATA[JCJ is an iphone front end for the popular medical locums job agency jcjlocums.co.uk. One of the main requirements was that the app be fun and easy to use which allowed Chris Baxter to use his creativity and come up with a really unique design.
The animated intro was achieved using CoreAnimation to drop UIButtons from the top [...]]]></description>
			<content:encoded><![CDATA[<p>JCJ is an iphone front end for the popular medical locums job agency <a href="http://www.jcjlocums.co.uk/">jcjlocums.co.uk</a>. One of the main requirements was that the app be fun and easy to use which allowed <a href="http://engineroomapps.com/">Chris Baxter</a> to use his creativity and come up with a really unique design.</p>
<p>The animated intro was achieved using <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreAnimation_guide/Introduction/Introduction.html">CoreAnimation</a> to drop UIButtons from the top of the screen. The &#8220;multi value fields&#8221; used in the search screen are simply UILabels embedded in a UIScrollview using the paging feature to provide smooth scrolling between values. There are existing Calendar libraries for the iphone however I decided in the end to write a custom control which allows much tighter integration into the design.</p>
<p><a href="http://itunes.apple.com/gb/artist/hcl-plc/id369346998">JCJ Locums app is available free on the app store</a></p>

<a href='http://benreeves.co.uk/jcj-locums-app/screen-shot-2010-05-08-at-13-31-53/' title='Screen shot 2010-05-08 at 13.31.53'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-08-at-13.31.53-150x150.png" class="attachment-thumbnail" alt="" title="Screen shot 2010-05-08 at 13.31.53" /></a>
<a href='http://benreeves.co.uk/jcj-locums-app/screen-shot-2010-05-08-at-13-32-08/' title='Screen shot 2010-05-08 at 13.32.08'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-08-at-13.32.08-150x150.png" class="attachment-thumbnail" alt="" title="Screen shot 2010-05-08 at 13.32.08" /></a>
<a href='http://benreeves.co.uk/jcj-locums-app/screen-shot-2010-05-08-at-13-32-18/' title='Screen shot 2010-05-08 at 13.32.18'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-08-at-13.32.18-150x150.png" class="attachment-thumbnail" alt="" title="Screen shot 2010-05-08 at 13.32.18" /></a>
<a href='http://benreeves.co.uk/jcj-locums-app/screen-shot-2010-05-08-at-13-32-33/' title='Screen shot 2010-05-08 at 13.32.33'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-08-at-13.32.33-150x150.png" class="attachment-thumbnail" alt="" title="Screen shot 2010-05-08 at 13.32.33" /></a>
<a href='http://benreeves.co.uk/jcj-locums-app/screen-shot-2010-05-08-at-13-33-04/' title='Screen shot 2010-05-08 at 13.33.04'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-08-at-13.33.04-150x150.png" class="attachment-thumbnail" alt="" title="Screen shot 2010-05-08 at 13.33.04" /></a>
<a href='http://benreeves.co.uk/jcj-locums-app/screen-shot-2010-05-08-at-13-33-13/' title='Screen shot 2010-05-08 at 13.33.13'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-08-at-13.33.13-150x150.png" class="attachment-thumbnail" alt="" title="Screen shot 2010-05-08 at 13.33.13" /></a>
<a href='http://benreeves.co.uk/jcj-locums-app/screen-shot-2010-05-08-at-13-33-17/' title='Screen shot 2010-05-08 at 13.33.17'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-08-at-13.33.17-150x150.png" class="attachment-thumbnail" alt="" title="Screen shot 2010-05-08 at 13.33.17" /></a>
<a href='http://benreeves.co.uk/jcj-locums-app/screen-shot-2010-05-08-at-13-33-24/' title='Screen shot 2010-05-08 at 13.33.24'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/05/Screen-shot-2010-05-08-at-13.33.24-150x150.png" class="attachment-thumbnail" alt="" title="Screen shot 2010-05-08 at 13.33.24" /></a>

]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/jcj-locums-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Objective C HMTL Parser</title>
		<link>http://benreeves.co.uk/objective-c-hmtl-parser/</link>
		<comments>http://benreeves.co.uk/objective-c-hmtl-parser/#comments</comments>
		<pubDate>Sat, 08 May 2010 13:03:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[html parser]]></category>
		<category><![CDATA[libxml]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[uiwebview]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://benreeves.co.uk/?p=286</guid>
		<description><![CDATA[Here is basic html parser which I&#8217;ve used in several projects recently. The code depends on libxml2 and is basically a thin wrapper that provides a more convenient interface for parsing html with objective c. This has only been tested on iphone OS 3.1.3 &#38; 3.2, if your using a OSX your probably better of [...]]]></description>
			<content:encoded><![CDATA[<p>Here is basic html parser which I&#8217;ve used in several projects recently. The code depends on <a href="http://xmlsoft.org/">libxml2</a> and is basically a thin wrapper that provides a more convenient interface for <strong>parsing html with objective c. </strong>This has only been tested on iphone OS 3.1.3 &amp; 3.2, if your using a OSX your probably better of investigating using Webkit to manipulate your DOM.</p>
<p>The code below is provided under an MIT license, but if you do make any updates it would be great if you could send them back.</p>
<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">   <span style="color: #11740a; font-style: italic;">//Example to download google's source and print out the urls of all the images</span>
   <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span> error <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
   HTMLParser <span style="color: #002200;">*</span> parser <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>HTMLParser alloc<span style="color: #002200;">&#93;</span> initWithContentsOfURL<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.google.com&quot;</span><span style="color: #002200;">&#93;</span> error<span style="color: #002200;">:&amp;</span>amp;error<span style="color: #002200;">&#93;</span>;
&nbsp;
   <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>error<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
     NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Error: %@&quot;</span>, error<span style="color: #002200;">&#41;</span>;
     <span style="color: #a61390;">return</span>;
  <span style="color: #002200;">&#125;</span>
  HTMLNode <span style="color: #002200;">*</span> bodyNode <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>parser body<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//Find the body tag</span>
&nbsp;
  <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span> imageNodes <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>bodyNode findChildTags<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;img&quot;</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//Get all the &lt;img alt=&quot;&quot; /&gt;</span>
&nbsp;
 <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>HTMLNode <span style="color: #002200;">*</span> imageNode <span style="color: #a61390;">in</span> imageNodes<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> <span style="color: #11740a; font-style: italic;">//Loop through all the tags</span>
       NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Found image with src: %@&quot;</span>, <span style="color: #002200;">&#91;</span>imageNode getAttributeNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;src&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">//Echo the src=&quot;&quot;</span>
  <span style="color: #002200;">&#125;</span>
&nbsp;
  <span style="color: #002200;">&#91;</span>parser release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p><strong>You can grab a copy of the code here on github:</strong><br />
<a href="http://github.com/zootreeves/Objective-C-HMTL-Parser ">http://github.com/zootreeves/Objective-C-HMTL-Parser</a><br />
git@github.com:zootreeves/Objective-C-HMTL-Parser.git</p>
<h4>Note:</h4>
<p>-(NSString*)rawContents; does not work, you need to use NSString * rawContentsOfNode(xmlNode * node, htmlDocPtr doc); to dump the entire html contents of a node.</p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/objective-c-hmtl-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iElect UK</title>
		<link>http://benreeves.co.uk/ielect-uk/</link>
		<comments>http://benreeves.co.uk/ielect-uk/#comments</comments>
		<pubDate>Sat, 08 May 2010 10:02:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://benreeves.co.uk/?p=265</guid>
		<description><![CDATA[iElect UK is an iPhone application with a unique concept. During the upcoming 2010 election users will be able to use iElect to lookup their constituency and view information about their current MP and 2010 candidates. Users can then request that candidates gets in touch with them by sms or email.
Again this project was undertaken [...]]]></description>
			<content:encoded><![CDATA[<p>iElect UK is an iPhone application with a unique concept. During the upcoming 2010 election users will be able to use iElect to lookup their constituency and view information about their current MP and 2010 candidates. Users can then request that candidates gets in touch with them by sms or email.</p>
<p>Again this project was undertaken with the guys at <a href="http://gedgers.com/">Gedgers</a> and <a href="http://engineroomapps.com/">engineroomapps</a>. Core location and the Mapkit API are used to pinpoint the users location and find their default constituency. Core data is then used to store the list of constituencies and candidates details. The contact feature issues a request to the backend web service, which will forward the provided details onto the candidate. The striking orange buttons and rounded containers are drawn using Quartz 2D.</p>

<a href='http://benreeves.co.uk/ielect-uk/screenshot-2010-03-21-11-18-08/' title='Screenshot 2010.03.21 11.18.08'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.21-11.18.08-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.21 11.18.08" /></a>
<a href='http://benreeves.co.uk/ielect-uk/screenshot-2010-03-21-11-18-17/' title='Screenshot 2010.03.21 11.18.17'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.21-11.18.17-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.21 11.18.17" /></a>
<a href='http://benreeves.co.uk/ielect-uk/screenshot-2010-03-21-11-18-44/' title='Screenshot 2010.03.21 11.18.44'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.21-11.18.44-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.21 11.18.44" /></a>
<a href='http://benreeves.co.uk/ielect-uk/screenshot-2010-03-21-11-19-03/' title='Screenshot 2010.03.21 11.19.03'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.21-11.19.03-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.21 11.19.03" /></a>
<a href='http://benreeves.co.uk/ielect-uk/screenshot-2010-03-21-11-19-16/' title='Screenshot 2010.03.21 11.19.16'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.21-11.19.16-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.21 11.19.16" /></a>
<a href='http://benreeves.co.uk/ielect-uk/screenshot-2010-03-21-11-19-22/' title='Screenshot 2010.03.21 11.19.22'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.21-11.19.22-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.21 11.19.22" /></a>

]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/ielect-uk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SieveHash &#8211; An alternative hash table implementation</title>
		<link>http://benreeves.co.uk/sievehash-an-alternative-hash-table-implementation/</link>
		<comments>http://benreeves.co.uk/sievehash-an-alternative-hash-table-implementation/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 16:20:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://benreeves.co.uk/?p=239</guid>
		<description><![CDATA[A fast and efficient C hash table implementation, which in many cases can beat google dense hash map, the STL Tr1 hash map and khash
The semi-interesting part is the way it handles collisions. When Sievehash encounters a collision is makes another hash table smaller than it&#8217;s parent. Each new key is dropped through the Seive [...]]]></description>
			<content:encoded><![CDATA[<p>A fast and efficient C hash table implementation, which in many cases can beat google dense hash map, the STL Tr1 hash map and khash</p>
<p>The semi-interesting part is the way it handles collisions. When Sievehash encounters a collision is makes another hash table smaller than it&#8217;s parent. Each new key is dropped through the Seive until an empty spot is found and becomes it&#8217;s new home, forming a structure like a Seive.</p>
<p>Similar to most hash tables, when any table reaches the specified load factor all keys will be copied to a new larger table.</p>
<p>Sieve Hash Library: <a href="http://benreeves.co.uk/wp-content/uploads/2010/02/SieveHash.h">SieveHash.h</a></p>
<p>Hash test package: <a href="http://benreeves.co.uk/wp-content/uploads/2010/03/HashTests.zip">HashTests</a></p>
<pre>*** Starting String Test: STL TR1
- Insert Took: 2.751855
- Lookup Took: 2.694130
} Test Took: 8.425282
*** Starting String Test: SieveHash
- Insert Took: 4.447270
- Lookup Took: 2.972444
} Test Took: 10.369791
*** Starting String Test: KHash CPP
- Insert Took: 2.676008
- Lookup Took: 3.056431
} Test Took: 8.704912
*** Starting String Test: Google Dense Hash Test
- Insert Took: 5.109226
- Lookup Took: 4.746739
} Test Took: 12.817609</pre>
<pre>WARNING: This is not meant for production code, it is for testing purposes only.</pre>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/sievehash-an-alternative-hash-table-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MyStacks &#8211; Stack Overflow trilogy app</title>
		<link>http://benreeves.co.uk/mystacks-stack-overflow-trilogy-app/</link>
		<comments>http://benreeves.co.uk/mystacks-stack-overflow-trilogy-app/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 16:09:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://benreeves.co.uk/?p=243</guid>
		<description><![CDATA[MyStacks is an iPhone application for browsing questions from the stack overflow trilogy sites, those are stackoverflow.com superuser.com serverfault.com and stackoverflow.com.
Features:

Themeable UI
DOM HTML parser
Save Questions Offline
Search AND, OR, Phrase, body and title
FREE!

At present the version available in store is v0.1, which does not include most of the features seen in the screenshots, an update has [...]]]></description>
			<content:encoded><![CDATA[<p>MyStacks is an iPhone application for browsing questions from the stack overflow trilogy sites, those are <a href="http://www.stackoverflow.com">stackoverflow.com</a> <a href="http://superuser.com/">superuser.com</a> <a href="http://serverfault.com/">serverfault.com</a> and <a href="http://meta.stackoverflow.com/">stackoverflow.com</a>.</p>
<p>Features:</p>
<ul>
<li>Themeable UI</li>
<li>DOM HTML parser</li>
<li>Save Questions Offline</li>
<li>Search AND, OR, Phrase, body and title</li>
<li><strong>FREE!</strong></li>
</ul>

<a href='http://benreeves.co.uk/mystacks-stack-overflow-trilogy-app/screenshot-2010-03-17-15-46-17/' title='Screenshot 2010.03.17 15.46.17'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.17-15.46.17-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.17 15.46.17" /></a>
<a href='http://benreeves.co.uk/mystacks-stack-overflow-trilogy-app/screenshot-2010-03-17-15-46-39/' title='Screenshot 2010.03.17 15.46.39'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.17-15.46.39-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.17 15.46.39" /></a>
<a href='http://benreeves.co.uk/mystacks-stack-overflow-trilogy-app/screenshot-2010-03-17-15-46-44/' title='Screenshot 2010.03.17 15.46.44'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.17-15.46.44-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.17 15.46.44" /></a>
<a href='http://benreeves.co.uk/mystacks-stack-overflow-trilogy-app/screenshot-2010-03-17-15-46-58/' title='Screenshot 2010.03.17 15.46.58'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.17-15.46.58-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.17 15.46.58" /></a>
<a href='http://benreeves.co.uk/mystacks-stack-overflow-trilogy-app/screenshot-2010-03-17-15-47-44/' title='Screenshot 2010.03.17 15.47.44'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.17-15.47.44-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.17 15.47.44" /></a>
<a href='http://benreeves.co.uk/mystacks-stack-overflow-trilogy-app/screenshot-2010-03-17-15-47-50/' title='Screenshot 2010.03.17 15.47.50'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/03/Screenshot-2010.03.17-15.47.50-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.17 15.47.50" /></a>

<p>At present the version available in store is v0.1, which does not include most of the features seen in the screenshots, an update has been submitted and will be available soon. In the meantime you can still download <a href="http://itunes.apple.com/us/app/stackoverflow/id360030953?mt=8">Stack Overflow v0.1 in the app store</a></p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/mystacks-stack-overflow-trilogy-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Business Desk iPhone app</title>
		<link>http://benreeves.co.uk/thebusinessdesk-com-iphone-news-app/</link>
		<comments>http://benreeves.co.uk/thebusinessdesk-com-iphone-news-app/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:43:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://benreeves.co.uk/?p=217</guid>
		<description><![CDATA[Specification

A user will be able to view news content whilst the application is on-line and off-line
A user will be able to share a news article by e-mail.
A user will launch the app and be able to read the latest news from The Business Desk
A user will view a headlines list to choose a full article [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Specification</p>
<ul>
<li>A user will be able to view news content whilst the application is on-line and off-line</li>
<li>A user will be able to share a news article by e-mail.</li>
<li>A user will launch the app and be able to read the latest news from The Business Desk</li>
<li>A user will view a headlines list to choose a full article to view.</li>
<li>A user can login</li>
</ul>
<p>Solution</p>
<p>I worked with the team at <a href="http://engineroomapps.com">engineroomapps.com</a> <<a href="http://engineroomapps.com">http://engineroomapps.com</a>> on this project using using agile development techniques and collaboration tools such as basecamp, git and targetprocess. The app front end interface and logic were development by me using objective c and the SDK 3.0 API. Initially the news data was proposed to be supplied using Ruby &amp; activeresource, however the library was eventually discarded due to stability issues. Instead the feed was provided by the web service team in xml format and parsed on the app side using touchxml. For offline viewing data is saved persistently using core data, reachability code is used to display when reading news online or offline.</p>

<a href='http://benreeves.co.uk/thebusinessdesk-com-iphone-news-app/screen-shot-2010-02-23-at-17-15-09/' title='Login Screenshot'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/02/Screen-shot-2010-02-23-at-17.15.09-150x150.png" class="attachment-thumbnail" alt="" title="Login Screenshot" /></a>
<a href='http://benreeves.co.uk/thebusinessdesk-com-iphone-news-app/screenshot-2010-03-21-11-10-55/' title='Screenshot 2010.03.21 11.10.55'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/02/Screenshot-2010.03.21-11.10.55-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.21 11.10.55" /></a>
<a href='http://benreeves.co.uk/thebusinessdesk-com-iphone-news-app/screenshot-2010-03-21-11-11-01/' title='Screenshot 2010.03.21 11.11.01'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/02/Screenshot-2010.03.21-11.11.01-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.21 11.11.01" /></a>
<a href='http://benreeves.co.uk/thebusinessdesk-com-iphone-news-app/screenshot-2010-03-26-11-22-42/' title='Screenshot 2010.03.26 11.22.42'><img width="150" height="150" src="http://benreeves.co.uk/wp-content/uploads/2010/02/Screenshot-2010.03.26-11.22.42-150x150.png" class="attachment-thumbnail" alt="" title="Screenshot 2010.03.26 11.22.42" /></a>

<p style="text-align: center; clear: both;"><a href="http://itunes.apple.com/gb/app/thebusinessdesk/id359890120?mt=8">The business desk app is available FREE in the app store</a></p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/thebusinessdesk-com-iphone-news-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reddit.com Clone In 4 Lines Of C</title>
		<link>http://benreeves.co.uk/reddit-com-clone-in-4-lines-of-c/</link>
		<comments>http://benreeves.co.uk/reddit-com-clone-in-4-lines-of-c/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 22:16:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://benreeves.co.uk/?p=197</guid>
		<description><![CDATA[
#include &#60;stdio.h&#62;
#include &#60;time.h&#62;
#include &#60;netinet/in.h&#62;
typedef struct &#123; int ID; char * title; char * link; char * date; int upVotes; int downVotes; void * next; &#125; Article; Article * root; char * getVal&#40;char * query, char * key&#41; &#123; char * str = malloc&#40;1&#41;; int match = 0; int pMatch = 0; char * cur = [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;time.h&gt;</span>
<span style="color: #339933;">#include &lt;netinet/in.h&gt;</span>
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">int</span> ID<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> title<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> link<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> date<span style="color: #339933;">;</span> <span style="color: #993333;">int</span> upVotes<span style="color: #339933;">;</span> <span style="color: #993333;">int</span> downVotes<span style="color: #339933;">;</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span> next<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> Article<span style="color: #339933;">;</span> Article <span style="color: #339933;">*</span> root<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> getVal<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span> query<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> key<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> str <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #993333;">int</span> match <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #993333;">int</span> pMatch <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> cur <span style="color: #339933;">=</span> query<span style="color: #339933;">;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>cur <span style="color: #339933;">!=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pMatch <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>cur <span style="color: #339933;">==</span> <span style="color: #ff0000;">'&amp;'</span> <span style="color: #339933;">||</span> <span style="color: #339933;">*</span>cur <span style="color: #339933;">==</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">||</span> <span style="color: #339933;">*</span>cur <span style="color: #339933;">==</span> <span style="color: #ff0000;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pMatch <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> str <span style="color: #339933;">=</span> realloc<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> pMatch<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>str<span style="color: #339933;">+</span>pMatch<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>cur<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>pMatch<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>match <span style="color: #339933;">==</span> strlen<span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> pMatch <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>cur <span style="color: #339933;">==</span> key<span style="color: #009900;">&#91;</span>match<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #339933;">++</span>match<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> match <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> cur<span style="color: #339933;">++;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pMatch <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> str<span style="color: #009900;">&#91;</span>pMatch<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span> str<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> free<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #993333;">char</span> from_hex<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> ch<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> isdigit<span style="color: #009900;">&#40;</span>ch<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> ch <span style="color: #339933;">-</span> <span style="color: #ff0000;">'0'</span> <span style="color: #339933;">:</span> tolower<span style="color: #009900;">&#40;</span>ch<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #ff0000;">'a'</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #993333;">char</span> to_hex<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> code<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">static</span> <span style="color: #993333;">char</span> hex<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;0123456789abcdef&quot;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span> hex<span style="color: #009900;">&#91;</span>code <span style="color: #339933;">&amp;</span> <span style="color: #0000dd;">15</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>url_decode<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>pstr <span style="color: #339933;">=</span> str<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>buf <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span>strlen<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #339933;">*</span>pbuf <span style="color: #339933;">=</span> buf<span style="color: #339933;">;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>pstr<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>pstr <span style="color: #339933;">==</span> <span style="color: #ff0000;">'%'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pstr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> pstr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #339933;">*</span>pbuf<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> from_hex<span style="color: #009900;">&#40;</span>pstr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">4</span> <span style="color: #339933;">|</span> from_hex<span style="color: #009900;">&#40;</span>pstr<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> pstr <span style="color: #339933;">+=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>pstr <span style="color: #339933;">==</span> <span style="color: #ff0000;">'+'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #339933;">*</span>pbuf<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">' '</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #339933;">*</span>pbuf<span style="color: #339933;">++</span> <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>pstr<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> pstr<span style="color: #339933;">++;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">*</span>pbuf <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span> buf<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #993333;">void</span> send_headers<span style="color: #009900;">&#40;</span>FILE <span style="color: #339933;">*</span>f<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> status<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>title<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>extra<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>mime<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> length<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">char</span> timebuf<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">128</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s %d %s<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;HTTP/1.0&quot;</span><span style="color: #339933;">,</span> status<span style="color: #339933;">,</span> title<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Server: %s<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;redditserver/1.0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>extra<span style="color: #009900;">&#41;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> extra<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>mime<span style="color: #009900;">&#41;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Content-Type: %s<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> mime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>length <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Content-Length: %d<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Connection: close<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #993333;">void</span> reddit<span style="color: #009900;">&#40;</span>FILE <span style="color: #339933;">*</span>f<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;Reddit Clone&lt;/TITLE&gt;&lt;/HEAD&gt;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;BODY&gt;&lt;H1&gt;Submit&lt;/H1&gt;&lt;form action=<span style="color: #000099; font-weight: bold;">\&quot;</span>/<span style="color: #000099; font-weight: bold;">\&quot;</span> method=<span style="color: #000099; font-weight: bold;">\&quot;</span>get<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Title:&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>title<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt; Link:&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>link<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>submit<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span>Submit<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;/form&gt;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>root<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;h1&gt;Articles&lt;/h1&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> Article <span style="color: #339933;">*</span> cur <span style="color: #339933;">=</span> root<span style="color: #339933;">;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>cur <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;p&gt;&lt;font size=<span style="color: #000099; font-weight: bold;">\&quot;</span>5<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;%d&lt;b&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>/?up=%d<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&amp;uarr&lt;/b&gt;&lt;/font&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>%s<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;%s&lt;/a&gt;&lt;br /&gt;&lt;font size=<span style="color: #000099; font-weight: bold;">\&quot;</span>5<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>/?down=%d<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&amp;darr&lt;/a&gt;&lt;/b&gt;&lt;/font&gt;%s -- %s&lt;/p&gt;&quot;</span><span style="color: #339933;">,</span> cur<span style="color: #339933;">-&gt;</span>upVotes <span style="color: #339933;">-</span> cur<span style="color: #339933;">-&gt;</span>downVotes<span style="color: #339933;">,</span> cur<span style="color: #339933;">-&gt;</span>ID<span style="color: #339933;">,</span> cur<span style="color: #339933;">-&gt;</span>link<span style="color: #339933;">,</span> cur<span style="color: #339933;">-&gt;</span>title<span style="color: #339933;">,</span> cur<span style="color: #339933;">-&gt;</span>ID<span style="color: #339933;">,</span> cur<span style="color: #339933;">-&gt;</span>link<span style="color: #339933;">,</span> cur<span style="color: #339933;">-&gt;</span>date<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> cur <span style="color: #339933;">=</span> cur<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>fprintf<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;/BODY&gt;&lt;/HTML&gt;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #993333;">int</span> fsize<span style="color: #009900;">&#40;</span>FILE <span style="color: #339933;">*</span> f<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> fseek<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> SEEK_END<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #993333;">int</span> size <span style="color: #339933;">=</span> ftell<span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> fseek<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> SEEK_SET<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span> size<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">int</span> sock<span style="color: #339933;">;</span> <span style="color: #993333;">int</span> port <span style="color: #339933;">=</span> <span style="color: #0000dd;">1337</span><span style="color: #339933;">;</span> <span style="color: #993333;">struct</span> sockaddr_in sin<span style="color: #339933;">;</span> sock <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span>AF_INET<span style="color: #339933;">,</span> SOCK_STREAM<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> sin.<span style="color: #202020;">sin_family</span> <span style="color: #339933;">=</span> AF_INET<span style="color: #339933;">;</span> sin.<span style="color: #202020;">sin_addr</span>.<span style="color: #202020;">s_addr</span> <span style="color: #339933;">=</span> INADDR_ANY<span style="color: #339933;">;</span> sin.<span style="color: #202020;">sin_port</span> <span style="color: #339933;">=</span> htons<span style="color: #009900;">&#40;</span>port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>bind<span style="color: #009900;">&#40;</span>sock<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> sockaddr <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>sin<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>sin<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Failed bind<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> sleep<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> listen<span style="color: #009900;">&#40;</span>sock<span style="color: #339933;">,</span> <span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;HTTP server listening on port %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> root <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">int</span> s<span style="color: #339933;">;</span> <span style="color: #993333;">int</span> size<span style="color: #339933;">;</span> <span style="color: #993333;">int</span> hsize<span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> buff<span style="color: #339933;">;</span> FILE <span style="color: #339933;">*</span> t<span style="color: #339933;">;</span> FILE <span style="color: #339933;">*</span> ht<span style="color: #339933;">;</span> FILE <span style="color: #339933;">*</span> f<span style="color: #339933;">;</span> s <span style="color: #339933;">=</span> accept<span style="color: #009900;">&#40;</span>sock<span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>s <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> header <span style="color: #339933;">=</span> calloc<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">255</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> size <span style="color: #339933;">=</span> read<span style="color: #009900;">&#40;</span>s<span style="color: #339933;">,</span> header<span style="color: #339933;">,</span> <span style="color: #0000dd;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> titleEnc <span style="color: #339933;">=</span> getVal<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> linkEnc <span style="color: #339933;">=</span> getVal<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>titleEnc <span style="color: #339933;">&amp;&amp;</span> linkEnc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> title <span style="color: #339933;">=</span> url_decode<span style="color: #009900;">&#40;</span>titleEnc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> link <span style="color: #339933;">=</span>  url_decode<span style="color: #009900;">&#40;</span>linkEnc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> free<span style="color: #009900;">&#40;</span>linkEnc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> free<span style="color: #009900;">&#40;</span>titleEnc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Title: %s -- Link: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> title<span style="color: #339933;">,</span> link<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #993333;">char</span>  <span style="color: #339933;">*</span> s <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> size_t i<span style="color: #339933;">;</span> <span style="color: #993333;">struct</span> tm tim<span style="color: #339933;">;</span> time_t now<span style="color: #339933;">;</span> now <span style="color: #339933;">=</span> time<span style="color: #009900;">&#40;</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> tim <span style="color: #339933;">=</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>localtime<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>now<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">=</span> strftime<span style="color: #009900;">&#40;</span>s<span style="color: #339933;">,</span><span style="color: #0000dd;">30</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;%b %d, %Y; %H:%M:%S<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,&amp;</span>tim<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> Article <span style="color: #339933;">*</span> new <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>Article<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> new<span style="color: #339933;">-&gt;</span>title <span style="color: #339933;">=</span> title<span style="color: #339933;">;</span> new<span style="color: #339933;">-&gt;</span>link <span style="color: #339933;">=</span> link<span style="color: #339933;">;</span> new<span style="color: #339933;">-&gt;</span>next <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span> new<span style="color: #339933;">-&gt;</span>date <span style="color: #339933;">=</span> s<span style="color: #339933;">;</span> new<span style="color: #339933;">-&gt;</span>upVotes <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> new<span style="color: #339933;">-&gt;</span>downVotes <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>root<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> root <span style="color: #339933;">=</span> new<span style="color: #339933;">;</span> new<span style="color: #339933;">-&gt;</span>ID <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">int</span> dupe <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> Article <span style="color: #339933;">*</span> cur <span style="color: #339933;">=</span> root<span style="color: #339933;">;</span> Article <span style="color: #339933;">*</span> prev <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>cur <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strcmp<span style="color: #009900;">&#40;</span>cur<span style="color: #339933;">-&gt;</span>title<span style="color: #339933;">,</span> new<span style="color: #339933;">-&gt;</span>title<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">||</span> strcmp<span style="color: #009900;">&#40;</span>cur<span style="color: #339933;">-&gt;</span>link<span style="color: #339933;">,</span> new<span style="color: #339933;">-&gt;</span>link<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> dupe <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> prev <span style="color: #339933;">=</span> cur<span style="color: #339933;">;</span> cur <span style="color: #339933;">=</span> cur<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>dupe <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> new<span style="color: #339933;">-&gt;</span>ID <span style="color: #339933;">=</span> prev<span style="color: #339933;">-&gt;</span>ID <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> prev<span style="color: #339933;">-&gt;</span>next <span style="color: #339933;">=</span> new<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> free<span style="color: #009900;">&#40;</span>new<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> upID <span style="color: #339933;">=</span> getVal<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;up&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>upID<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">int</span> ID <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>upID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> Article <span style="color: #339933;">*</span> cur <span style="color: #339933;">=</span> root<span style="color: #339933;">;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>cur <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>cur<span style="color: #339933;">-&gt;</span>ID <span style="color: #339933;">==</span> ID<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> cur<span style="color: #339933;">-&gt;</span>upVotes<span style="color: #339933;">++;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> cur <span style="color: #339933;">=</span> cur<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> dID <span style="color: #339933;">=</span> getVal<span style="color: #009900;">&#40;</span>header<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;down&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>dID<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #993333;">int</span> ID <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>dID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> Article <span style="color: #339933;">*</span> cur <span style="color: #339933;">=</span> root<span style="color: #339933;">;</span>  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>cur <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>cur<span style="color: #339933;">-&gt;</span>ID <span style="color: #339933;">==</span> ID<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> cur<span style="color: #339933;">-&gt;</span>downVotes<span style="color: #339933;">++;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> cur <span style="color: #339933;">=</span> cur<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> t <span style="color: #339933;">=</span> tmpfile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> ht <span style="color: #339933;">=</span> tmpfile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> reddit<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> size <span style="color: #339933;">=</span> fsize<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> send_headers<span style="color: #009900;">&#40;</span>ht<span style="color: #339933;">,</span> <span style="color: #0000dd;">200</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Ok&quot;</span><span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;text/html&quot;</span><span style="color: #339933;">,</span> size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> hsize <span style="color: #339933;">=</span> fsize<span style="color: #009900;">&#40;</span>ht<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> buff <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span>hsize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> fread<span style="color: #009900;">&#40;</span>buff<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> hsize<span style="color: #339933;">,</span> ht<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> write<span style="color: #009900;">&#40;</span>s<span style="color: #339933;">,</span>buff<span style="color: #339933;">,</span>hsize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> free<span style="color: #009900;">&#40;</span>buff<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> buff <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> fread<span style="color: #009900;">&#40;</span>buff<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> size<span style="color: #339933;">,</span> t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> write<span style="color: #009900;">&#40;</span>s<span style="color: #339933;">,</span>buff<span style="color: #339933;">,</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> free<span style="color: #009900;">&#40;</span>buff<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> fclose<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: center;"><a href="http://benreeves.co.uk/wp-content/uploads/2010/02/Screen-shot-2010-02-05-at-21.53.28.png"><img class="aligncenter size-full wp-image-201" title="Reddit_Screenshot" src="http://benreeves.co.uk/wp-content/uploads/2010/02/Screen-shot-2010-02-05-at-21.53.28.png" alt="" width="618" height="412" /></a></p>
<p><em> $ gcc reddit.c -o reddit<br />
$ ./reddit<br />
HTTP server listening on port 1337 &#8212; </em><a href="http://localhost:1337/" target="_blank" class="broken_link"><em>http://localhost:1337/</em></a></p>
<p><a href="http://benreeves.co.uk/wp-content/uploads/2010/02/reddit.c">reddit.c</a></p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/reddit-com-clone-in-4-lines-of-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multithreading with core Data</title>
		<link>http://benreeves.co.uk/multithreading-with-core-data/</link>
		<comments>http://benreeves.co.uk/multithreading-with-core-data/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 17:23:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[core data]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[sqllite]]></category>

		<guid isPermaLink="false">http://benreeves.co.uk/?p=188</guid>
		<description><![CDATA[Working with core data in a multi threaded environment you have to extremely careful
For example if were creating a news application, we want to be able to import news in the background and display updates to the user with no interruption of the GUI. The task can be divided into several stages:

Download the xml feed [...]]]></description>
			<content:encoded><![CDATA[<p>Working with core data in a multi threaded environment you have to extremely careful</p>
<p>For example if were creating a news application, we want to be able to import news in the background and display updates to the user with no interruption of the GUI. The task can be divided into several stages:</p>
<ol>
<li>Download the xml feed with the latest news</li>
<li>Parse the feed</li>
<li>Insert the articles into core data</li>
<li>Notify the UI and refresh the display.</li>
</ol>
<p>We already have our core data API defined. A simple method to retrieve all the articles and a method to add a new article.<br />
DataSource.h</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> DataSource <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span> <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>getNewsFor<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>region;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>addArticle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Article<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>article forRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>region;
<span style="color: #a61390;">@end</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Now suppose we want to the web service to import the latest articles. We might define our implementation something like this:<br />
WebService.h</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> WebService <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
	<span style="color: #a61390;">id</span> delegate;
	LocalDataSource <span style="color: #002200;">*</span> source;
<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: #a61390;">id</span> delegate;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> LocalDataSource <span style="color: #002200;">*</span> source;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>importNewsForRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>region;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Our implementation of importNewsForRegion would look something like this:</p>
<p>WebService.m</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>importNewsForRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>region
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">//Perform in background if called from main</span>
	 <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> currentThread<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> mainThread<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>self performSelectorInBackground<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>importNewsForRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> withObject<span style="color: #002200;">:</span>region<span style="color: #002200;">&#93;</span>;
		 <span style="color: #a61390;">return</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">//Setup pool</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: #400080;">NSArray</span> <span style="color: #002200;">*</span> articles <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>XML parseArticleFeed<span style="color: #002200;">:</span>region.feedURL<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//Not safe 1.</span>
	 <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>Article <span style="color: #002200;">*</span> article <span style="color: #a61390;">in</span> articles<span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>source addArticle<span style="color: #002200;">:</span>article forRegion<span style="color: #002200;">:</span>region<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//Not safe 2.</span>
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #002200;">&#91;</span>delegate finishedImport<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//Not safe 3.</span>
	<span style="color: #002200;">&#91;</span>pool drain<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>However this because importNewsForRegion is running in a separate thread this is unsafe and will likely cause core data to crash or corrupt our database.</p>
<ol>
<li>The region passed to to importNews has likely come from a core data context which was constructed on the main thread. Even though were not even altering the region directly with core data it&#8217;s not safe to even read the feedURL, because every operation can trigger faulting.</li>
<li>When we instruct the source to add an article it will use the main threads context, this is fine when we are in the main thread, but in a background thread we need to specify our own context.</li>
<li>Not related to core data, but when we notify the delegate it will likely perform UI updates which are not safe to perform in a background thread. we need to ensure the delegate only received notifications on the main thread.</li>
</ol>
<p>To make our program thread safe we first need to make some small alterations to our API.</p>
<p>DataSource.h</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> DataSource <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span> <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>getNewsFor<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>region;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>getNewsFor<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>region context<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSManagedObjectContext</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>context;
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>addArticle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Article<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>article forRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>region;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>addArticle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Article<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>article forRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>region context<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSManagedObjectContext</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>context;
<span style="color: #a61390;">@end</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>In our data source we specify two more methods which allow us to provide a context for the method to use. All our queries should be updated to only use the provided context. The original methods that don&#8217;t specify a context should call the newly implemented method with the default context, e.g.</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>addArticle<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Article<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>article forRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>region
<span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>self addArticle<span style="color: #002200;">:</span>article forRegion<span style="color: #002200;">:</span>region context<span style="color: #002200;">:</span>mainThreadContext<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Only when we are using core data in a background thread do we need to use the newly added methods. So we can now update our WebService.m:</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>importNewsForRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>unsafeRegion
<span style="color: #002200;">&#123;</span>
	<span style="color: #11740a; font-style: italic;">//Perform in background if called from main</span>
	 <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> currentThread<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> mainThread<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		<span style="color: #002200;">&#91;</span>self performSelectorInBackground<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>importNewsForRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> withObject<span style="color: #002200;">:</span> unsafeRegion<span style="color: #002200;">&#93;</span>;
		 <span style="color: #a61390;">return</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">//Setup pool</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;">//Create a new context just for this thread</span>
	<span style="color: #400080;">NSManagedObjectContext</span> <span style="color: #002200;">*</span> managedObjectContext <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSManagedObjectContext</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>managedObjectContext setPersistentStoreCoordinator<span style="color: #002200;">:</span>  <span style="color: #002200;">&#91;</span>source persistentStoreCoordinator<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #11740a; font-style: italic;">//Create a new region which is safe to use in this thread</span>
	Region <span style="color: #002200;">*</span> region <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>Region<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>managedObjectContext existingObjectWithID<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>unsafeRegion objectID<span style="color: #002200;">&#93;</span> error<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	 <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span> articles <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>XML parseArticleFeed<span style="color: #002200;">:</span>region.feedURL<span style="color: #002200;">&#93;</span>;
	 <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>Article <span style="color: #002200;">*</span> article <span style="color: #a61390;">in</span> articles<span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
               <span style="color: #11740a; font-style: italic;">//Ensure we provide the context for the source to use</span>
		<span style="color: #002200;">&#91;</span>source addArticle<span style="color: #002200;">:</span>article forRegion<span style="color: #002200;">:</span>region context<span style="color: #002200;">:</span>managedObjectContext<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#125;</span>
&nbsp;
	<span style="color: #11740a; font-style: italic;">//Save changes and close the new context</span>
	<span style="color: #002200;">&#91;</span>managedObjectContext save<span style="color: #002200;">:&amp;</span>amp;error<span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>managedObjectContext release<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>delegate performSelectorOnMainThread<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>finishedImport<span style="color: #002200;">&#41;</span> withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> waitUntilDone<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>pool drain<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>As you can see we crate a new context using out shared persistentStoreCoordinator, we ensure that anytime we touch core data from this thread we are using this context. The also means that we have to create a new region which belongs to this context, and we do this with the existingObjectWithID method and using the [unsafeRegion objectID]. Finally we ensure that the delegate receives the notification on the main thread.</p>
<p>for more information about threading in core data see:</p>
<p>http://developer.apple.com/Mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdMultiThreading.html</p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/multithreading-with-core-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocos2d iphone tutorial</title>
		<link>http://benreeves.co.uk/cocos2d-iphone-tutorial/</link>
		<comments>http://benreeves.co.uk/cocos2d-iphone-tutorial/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 00:26:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.benreeves.co.uk/?p=172</guid>
		<description><![CDATA[Cocos2d is a popular 2d framework for developing iphone games, including physics and particle support.  Here&#8217;s a quick introduction to getting cocos2d for the iphone up and running for your next project.
Download the latest source from:
http://code.google.com/p/cocos2d-iphone/downloads/list
I recommend you stick with the stable releases, unless there is a specific feature your require from a new version.
Unzip [...]]]></description>
			<content:encoded><![CDATA[<p>Cocos2d is a popular 2d framework for developing iphone games, including physics and particle support.  Here&#8217;s a quick introduction to getting cocos2d for the iphone up and running for your next project.</p>
<p>Download the latest source from:</p>
<p><a href="http://code.google.com/p/cocos2d-iphone/downloads/list">http://code.google.com/p/cocos2d-iphone/downloads/list</a></p>
<p>I recommend you stick with the stable releases, unless there is a specific feature your require from a new version.</p>
<p>Unzip the folder and the template installation script:</p>
<pre>$ ./install_template.sh</pre>
<p>This will make a series of cocos-2d templates available from XCode.  Launch/restart xcode and choose File-&gt;New Project-&gt;cocos2d Application build and run the new application in the simulator and it should look something like this:</p>
<p style="text-align: center;"><a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/Screen-shot-2010-01-27-at-00.04.39.png"><img class="size-full wp-image-173  aligncenter" title="Hello World cocos2d" src="http://www.benreeves.co.uk/wp-content/uploads/2010/01/Screen-shot-2010-01-27-at-00.04.39.png" alt="" width="539" height="290" /></a></p>
<p style="text-align: left;">Were going to build on this template to add a main menu</p>
<p style="text-align: left;">First download the test image and add it to the new xcode project (Make sure it is copied into the application directory)</p>
<p style="text-align: center;"><a style="text-decoration: none;" href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/MainMenuBackground.png"><img class="size-thumbnail wp-image-177  aligncenter" title="MainMenuBackground" src="http://www.benreeves.co.uk/wp-content/uploads/2010/01/MainMenuBackground-150x150.png" alt="" width="150" height="150" /></a></p>
<p style="text-align: left;">Create a new class name MenuScene and add the following code to the header file:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import</span>
<span style="color: #6e371a;">#import &quot;cocos2d.h&quot;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> MenuScene <span style="color: #002200;">:</span> Scene
<span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@interface</span> MenuLayer <span style="color: #002200;">:</span> Layer
<span style="color: #002200;">&#123;</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>startGame<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>help<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>The add the following to the .m file:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;MenuScene&quot;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> MenuScene
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init
<span style="color: #002200;">&#123;</span>
    self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        Sprite <span style="color: #002200;">*</span> bg <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Sprite spriteWithFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MainMenuBackground.png&quot;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>bg setPosition<span style="color: #002200;">:</span>ccp<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">160</span>, <span style="color: #2400d9;">240</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>bg z<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>MenuLayer node<span style="color: #002200;">&#93;</span> z<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> MenuLayer
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span> init
<span style="color: #002200;">&#123;</span>
    self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>MenuItemFont setFontSize<span style="color: #002200;">:</span><span style="color: #2400d9;">24</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>MenuItemFont setFontName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Helvetica&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
        MenuItem <span style="color: #002200;">*</span>start <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MenuItemFont itemFromString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Start Game&quot;</span>
												target<span style="color: #002200;">:</span>self
											  selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>startGame<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
        MenuItem <span style="color: #002200;">*</span>help <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MenuItemFont itemFromString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Help&quot;</span>
											   target<span style="color: #002200;">:</span>self
											 selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>help<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
        Menu <span style="color: #002200;">*</span>menu <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Menu menuWithItems<span style="color: #002200;">:</span>start, help, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
		menu.color <span style="color: #002200;">=</span> ccc3<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
        <span style="color: #002200;">&#91;</span>menu alignItemsVertically<span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>self addChild<span style="color: #002200;">:</span>menu<span style="color: #002200;">&#93;</span>;
    <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>startGame<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender
<span style="color: #002200;">&#123;</span>
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;start game&quot;</span><span style="color: #002200;">&#41;</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>help<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>sender <span style="color: #002200;">&#123;</span>
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;help&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Finally modify the app delegate (CocosTestAppDelegate.m) to include MenuScene.h</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;MainMenuScene.h&quot;</span></pre></div></div>

<p>and replace the line:</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>Director sharedDirector<span style="color: #002200;">&#93;</span> runWithScene<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>HelloWorld scene<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>with:</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>Director sharedDirector<span style="color: #002200;">&#93;</span> runWithScene<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>MenuScene node<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>also remove the line:</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>Director sharedDirector<span style="color: #002200;">&#93;</span> setDeviceOrientation<span style="color: #002200;">:</span>CCDeviceOrientationLandscapeLeft<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Compile and run the project and you should end up with a menu and two clickable buttons:</p>
<p style="text-align: center;"><a style="text-decoration: none;" href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/Screen-shot-2010-01-27-at-00.24.19.png"><img class="size-medium wp-image-178  aligncenter" title="Result" src="http://www.benreeves.co.uk/wp-content/uploads/2010/01/Screen-shot-2010-01-27-at-00.24.19-161x300.png" alt="" width="161" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/cocos2d-iphone-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Review of Wordpress 2.9.1 (So Far)</title>
		<link>http://benreeves.co.uk/my-review-of-wordpress-2-9-1-so-far/</link>
		<comments>http://benreeves.co.uk/my-review-of-wordpress-2-9-1-so-far/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 23:12:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[blogging software]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress vs drupal]]></category>

		<guid isPermaLink="false">http://www.benreeves.co.uk/?p=156</guid>
		<description><![CDATA[I&#8217;ve been meaning to redesign benreeves.co.uk for a while, however there were two things stopping me:

Graphics / Html have never been my strong point. Sure I can cut and paste from other designs and cobble together something which resembles a web page, but they always look just that, cobbled together.
It doesn&#8217;t get much traffic or [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been meaning to redesign benreeves.co.uk for a while, however there were two things stopping me:</p>
<ul>
<li>Graphics / Html have never been my strong point. Sure I can cut and paste from other designs and cobble together something which resembles a web page, but they always look just that, cobbled together.</li>
<li>It doesn&#8217;t get much traffic or provide much business value at present and hence I don&#8217;t want to have to pay a designer.</li>
</ul>
<p>I had previously used iWeb and then up until recently rapidweaver, these applications are fine up to a point, but soon there lack of advanced features and template editing becomes apparent.  Between an application like iWeb and designing the site from scratch we have content management systems (CMS), the most popular being Drupal, Joomla and wordpress.</p>
<p>I had heard good reviews of Drupal before so this was my first port of call. I won&#8217;t go into detail about the setup, but it was overall fairly straight forward, however after that things went downhill. The admin panel was confusing and slow, I spent several hours trying to get the sites navigation and content to resemble something how I wanted. It seemed like every theme I tried ended up looking like the same boxy layout, you could immediately tell the site was using drupal. The themes were poor quality, difficult to modify and modules were complicated to install. After my drupal experience I gave up on CMS for a while.</p>
<p>Today I decided to give wordpress a shot. Since I already had php setup, Installation really was a case on unpacking the zip file and placing it in the apache home directory. I immediately went to install a new template. Wordpress features an automatic template installation system, however this is where I hit my first stumbling block. Wordpress kept asking for my ftp information, however a quick google search revealed my file permissions were wrong.</p>
<p style="text-align: center;"><a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/connecinfo-300x176.jpg"><img class="size-full wp-image-158  aligncenter" title="Wordpress asking for ftp connection" src="http://www.benreeves.co.uk/wp-content/uploads/2010/01/connecinfo-300x176.jpg" alt="" width="300" height="176" /></a></p>
<p style="text-align: center;">The following command did the trick: <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">sudo chmod -R 777 /Path/To/Wordpress</span></p>
<p>Other than that templates where easy to install and I had found several decent looking ones in a few minutes. The next task was to add a contact page, unfortunatly wordpress doesn&#8217;t come with one as standard however the plugin &#8220;Contact Form 7&#8243; was easy to install without leaving the admin interface. Even the more advanced task of separating the wordpress blog into two different pages (see <a href="http://codex.wordpress.org/The_Loop">The Loop</a>) could be done without leaving the admin interface.</p>
<p>Overall I have been extremely impressed so, maybe I&#8217;ll run into customisation limitations again later, however at the moment I can&#8217;t praise wordpress enough.</p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/my-review-of-wordpress-2-9-1-so-far/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Reachability Code to your app</title>
		<link>http://benreeves.co.uk/adding-reachability-code-to-your-app/</link>
		<comments>http://benreeves.co.uk/adding-reachability-code-to-your-app/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 19:37:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.benreeves.co.uk/?p=130</guid>
		<description><![CDATA[Ok so iVersion 1.4 was declined due to not loading correctly when their is no network connectivity.
When the device is connected to a cellular network, iVersion does not load its contents.  After the user enters the URL (http://svn.collab.net/repos/svn/trunk/) and taps &#8220;connect,&#8221; an error message is received.
Apparently the error message is not clear enough or something, anyway this [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so iVersion 1.4 was declined due to not loading correctly when their is no network connectivity.</p>
<blockquote><p>When the device is connected to a cellular network, iVersion does not load its contents.  After the user enters the URL (<a href="http://svn.collab.net/repos/svn/trunk/" target="_blank" class="broken_link">http://svn.collab.net/repos/svn/trunk/</a>) and taps &#8220;connect,&#8221; an error message is received.</p></blockquote>
<p>Apparently the error message is not clear enough or something, anyway this is not a rant, this is what apple recommends.</p>
<blockquote><p>Please take a look at the Reachability iPhone program sample which demonstrates the use of the System Configuration Reachability API to detect the absence of WiFi and Wireless Wide Area Network (WWAN) services. Your application can then take appropriate action at the first point where network services are required.</p></blockquote>
<p>The sample code can be found on Apple developer site, however the two file we are interested in are:</p>
<p><strong>Download the Reachability Code:</strong><br />
<a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/Reachability.h">Reachability.h</a></p>
<p><a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/Reachability.m">Reachability.m</a></p>
<p><strong>How to use:</strong><br />
Lets say you have a simple UILabel which you want to update with either &#8220;(Offline)&#8221; or &#8220;(Online)&#8221; depending on whether the network is reachable. Your view controller would be defined something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> MyStatusView <span style="color: #002200;">:</span> UIViewController
<span style="color: #002200;">&#123;</span>
	UILabel <span style="color: #002200;">*</span> statusLabel;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span><span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> IBOutlet UILabel <span style="color: #002200;">*</span> statusLabel;
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>reachabilityChanged<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNotification</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>note;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>updateStatus;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Then we add the following code to the view controller .m file:</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>viewWillAppear<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated
<span style="color: #002200;">&#123;</span>
	self.reachability <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>Reachability reachabilityWithHostName<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;google.com&quot;</span><span style="color: #002200;">&#93;</span>;
	<span style="color: #002200;">&#91;</span>reachability startNotifer<span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> addObserver<span style="color: #002200;">:</span>self selector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>reachabilityChanged<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> name<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;kNetworkReachabilityChangedNotification&quot;</span> object<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
	<span style="color: #002200;">&#91;</span>self updateStatus<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>viewWillDisappear<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated
<span style="color: #002200;">&#123;</span>
	self.reachability <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
	<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNotificationCenter</span> defaultCenter<span style="color: #002200;">&#93;</span> removeObserver<span style="color: #002200;">:</span>self<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>reachabilityChanged<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSNotification</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>notification
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>self updateStatus<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>updateStatus
<span style="color: #002200;">&#123;</span>
	NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Reachability changed&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
	<span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>reachability currentReachabilityStatus<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> NotReachable<span style="color: #002200;">&#41;</span>
	<span style="color: #002200;">&#123;</span>
		statusLabel.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;(Offline)&quot;</span>;
	<span style="color: #002200;">&#125;</span>
	<span style="color: #a61390;">else</span>
	<span style="color: #002200;">&#123;</span>
		statusLabel.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;(Online)&quot;</span>;
	<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>I think it&#8217;s fairly self explanatory. Basically when the view appears the reachability class is created and started using startNotifier. Then we hook in our reachabilityChanged: method into the notification centre, so it is automatically called when the network status changes. reachabilityChanged: calls updateStatus which simply changes our label depending on the connectivity.</p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/adding-reachability-code-to-your-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UIKit Modal Prompt</title>
		<link>http://benreeves.co.uk/uikit-modal-prompt/</link>
		<comments>http://benreeves.co.uk/uikit-modal-prompt/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 19:20:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[modal prompt]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.benreeves.co.uk/?p=121</guid>
		<description><![CDATA[in order to not lock the ui iVersion runs it&#8217;s svn commands in a seperate threads. The promblem arises when one of thses threads needs to prompt for a value e.g. a username / password. Firstly UIKit does not provide a modal alert view and secondly UIKit should only be called from the mainThread.
First we [...]]]></description>
			<content:encoded><![CDATA[<p>in order to not lock the ui iVersion runs it&#8217;s svn commands in a seperate threads. The promblem arises when one of thses threads needs to prompt for a value e.g. a username / password. Firstly UIKit does not provide a modal alert view and secondly UIKit should only be called from the mainThread.</p>
<p>First we create a new class which has a view which will be loaded from a nib, a thread condition to lock the calling thread and two NSString fields to store the result and the string of the button which was clicked.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> MessagePrompt <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span>
<span style="color: #002200;">&#123;</span>
&nbsp;
UIView <span style="color: #002200;">*</span> view;
<span style="color: #400080;">NSCondition</span> <span style="color: #002200;">*</span> promptCondition;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> clickedButton Text;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> result;
<span style="color: #002200;">&#123;</span>
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Our new prompt method can be called from the thread which needs to be locked, it will subsequently call UIKit on the main thread.</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;">id</span><span style="color: #002200;">&#41;</span>newPrompt<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MessagePrompt<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>prompt
<span style="color: #002200;">&#123;</span>
&nbsp;
     <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> currentThread<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSThread</span> mainThread<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
          <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Should not be called by Main thread<span style="color: #2400d9;">\n</span>&quot;</span><span style="color: #002200;">&#41;</span>;
          <span style="color: #a61390;">return</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
     prompt.promptCondition <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSCondition</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>prompt performSelectorOnMainThread<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>prompt<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> withObject<span style="color: #002200;">:</span>view waitUntilDone<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>prompt.promptCondition wait<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> prompt;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This method is called by +(id)NewPrompt and displays a prompt in our window. It also adds targets to each UIButton to receive user actions.</p>
<p style="text-align: center;"><a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/screen-shot-2009-10-23-at-15.44.00.png"><img class="size-full wp-image-123  aligncenter" title="Prompt Nib Example" src="http://www.benreeves.co.uk/wp-content/uploads/2010/01/screen-shot-2009-10-23-at-15.44.00.png" alt="" width="380" height="269" /></a></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>prompt<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIView<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>inView
<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;MyPromptView&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>;
     inView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>nib objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;	
&nbsp;
     <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span> subviews <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.view subviews<span style="color: #002200;">&#93;</span>;
     <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span>UIView <span style="color: #002200;">*</span> cview <span style="color: #a61390;">in</span> subviews<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>cview isKindOfClass<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIButton 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>
               UIButton <span style="color: #002200;">*</span> button <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UIButton<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>cview;
                <span style="color: #002200;">&#91;</span>button addTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>clicked<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span> forControlEvents<span style="color: #002200;">:</span>UIControlEventTouchDown<span style="color: #002200;">&#93;</span>;
          <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #002200;">&#91;</span>inView.superview addSubview<span style="color: #002200;">:</span>view<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This is called when a user clicks a button, it finds the value field and retreives and stores the value in self.message. The prompt condition is then signalled which causes the calling thread to continue running.</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>IBAction<span style="color: #002200;">&#41;</span>clicked<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIButton<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>sender
<span style="color: #002200;">&#123;</span>
     self.clickedButton <span style="color: #002200;">=</span> sender.currentTitle;
&nbsp;
     UITextView <span style="color: #002200;">*</span> text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>iVersionAppDelegate findSubViewOfKind<span style="color: #002200;">:</span>self.view class<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UITextView class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
     <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>text<span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
         self.message <span style="color: #002200;">=</span> text.text;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #002200;">&#91;</span>self.view removeFromSuperview<span style="color: #002200;">&#93;</span>;
     self.view <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>promptCondition <span style="color: #a61390;">signal</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Usage</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">/* Called when svn requires a log message */</span>
svn_error_t <span style="color: #002200;">*</span>
iversion_svn_cl__get_log_message<span style="color: #002200;">&#40;</span><span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">**</span>log_msg,
<span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">**</span>tmp_file,
<span style="color: #a61390;">const</span> apr_array_header_t <span style="color: #002200;">*</span>commit_items,
<span style="color: #a61390;">void</span> <span style="color: #002200;">*</span>baton,
apr_pool_t <span style="color: #002200;">*</span>pool<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
&nbsp;
CommitLogMessagePrompt <span style="color: #002200;">*</span> prompt <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CommitLogMessagePrompt newPrompt<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">/* Clicked Continue */</span>
     <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>prompt.clickedButton isEqualToString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Continue&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">*</span>log_msg <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>prompt.message UTF8String<span style="color: #002200;">&#93;</span>;
         <span style="color: #a61390;">return</span> SVN_NO_ERROR;
    <span style="color: #002200;">&#125;</span>
&nbsp;
     <span style="color: #a61390;">return</span> svn_error_create<span style="color: #002200;">&#40;</span>SVN_ERR_CANCELLED, <span style="color: #a61390;">NULL</span>, _<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Delete Cancelled&quot;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/uikit-modal-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone File System Monitor</title>
		<link>http://benreeves.co.uk/iphone-file-system-monitor/</link>
		<comments>http://benreeves.co.uk/iphone-file-system-monitor/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 19:04:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[file monitor]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.benreeves.co.uk/?p=111</guid>
		<description><![CDATA[I require simple for system monitoring for a new (undisclosed) iphone project. It doesn&#8217;t appear that there is any equivilant to ionotify for the iphone, so I whipped up this polling file system monitor which meets my basic requirements. If you find this code useful feel free to use / distribute etc.

#include &#34;FileSystemMonitor.h&#34;
&#160;
//Setup the monitor
FileSystemMonitor [...]]]></description>
			<content:encoded><![CDATA[<p>I require simple for system monitoring for a new (undisclosed) iphone project. It doesn&#8217;t appear that there is any equivilant to ionotify for the iphone, so I whipped up this polling file system monitor which meets my basic requirements. If you find this code useful feel free to use / distribute etc.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#include &quot;FileSystemMonitor.h&quot;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//Setup the monitor</span>
FileSystemMonitor <span style="color: #002200;">*</span> monitor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>FileSystemMonitor alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
monitor.delegate <span style="color: #002200;">=</span> self;
<span style="color: #002200;">&#91;</span>monitor monitorPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;/&quot;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">//...In your delegate class</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>nodeWasCreatedAt<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>path
<span style="color: #002200;">&#123;</span>
     <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Created %s<span style="color: #2400d9;">\n</span>&quot;</span>, <span style="color: #002200;">&#91;</span>path UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</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>nodeWasDeletedAt<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>path
<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Deleted %s<span style="color: #2400d9;">\n</span>&quot;</span>, <span style="color: #002200;">&#91;</span>path UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</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>fileSizeDidchange<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>path bytes<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">size_t</span><span style="color: #002200;">&#41;</span>difference
<span style="color: #002200;">&#123;</span>
     <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;file Added %ul bytes<span style="color: #2400d9;">\n</span>&quot;</span>, difference<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><strong>Notes:</strong></p>
<ul>
<li>Can monitor for Deleted files, Created Files and File Size Changes</li>
<li>On an iPhone 3GS it is able to monitor the entire SVN 1.6 source tree and the iVersion source tree (total 11,050 File/Directories) in an execution time of 12s. Due to the low thread priority and the fact that the majority of execution time is IO it does not cause much/any slow down to the UI. However there is still room for improvement.</li>
</ul>
<p><strong>Download:</strong></p>
<p><strong><a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/FileSystemMonitor.h">FileSystemMonitor.h</a></strong></p>
<p><strong><a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/FileSystemMonitor.m">FileSystemMonitor.m</a></strong></p>
<p><strong><a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/FileMonitorDelegateProtocol.h">FileMonitorDelegateProtocol.h</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/iphone-file-system-monitor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Arrays with C</title>
		<link>http://benreeves.co.uk/dynamic-arrays-with-c/</link>
		<comments>http://benreeves.co.uk/dynamic-arrays-with-c/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 17:12:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dynamic arrays]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=81</guid>
		<description><![CDATA[In the final push to add syntax highlighting to iVersion I have been working on optimising the parser.
In the inner parsing loop I have been using the standard NSMutableArray to keep track of various objects and tokens. Objective C message passing is of course an order of times slower than a C function call, even [...]]]></description>
			<content:encoded><![CDATA[<p>In the final push to add syntax highlighting to iVersion I have been working on optimising the parser.</p>
<p>In the inner parsing loop I have been using the standard NSMutableArray to keep track of various objects and tokens. Objective C message passing is of course an order of times slower than a C function call, even if purely for the fact that they can’t be inlined. A great article that explains more about the objective c runtime an be found on the <a href="http://cocoasamurai.blogspot.com/2010/01/understanding-objective-c-runtime.html" target="_blank">cocoa samurai blog</a></p>
<p>So I decided to drop down to a dynamic array using plain C. However even though I’m sure dynamic arrays have been implement thousands of times I couldn’t seem to find any simple implementations.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">//** Usage</span>
<span style="color: #11740a; font-style: italic;">//Create an array with capacity 2</span>
CArray <span style="color: #002200;">*</span> array <span style="color: #002200;">=</span> CArrayInit<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Add two buckets</span>
CArrayAdd<span style="color: #002200;">&#40;</span>array, <span style="color: #bf1d1a;">&quot;test&quot;</span><span style="color: #002200;">&#41;</span>;
CArrayAdd<span style="color: #002200;">&#40;</span>array, <span style="color: #bf1d1a;">&quot;another test&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Add another and it will resize accordingly</span>
CArrayAdd<span style="color: #002200;">&#40;</span>array, <span style="color: #bf1d1a;">&quot;yet another&quot;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Print All</span>
<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> ii <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; ii <span style="color: #002200;">&amp;</span>lt; array<span style="color: #002200;">-&amp;</span>gt;count; <span style="color: #002200;">++</span>ii<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span> buffer <span style="color: #002200;">=</span> CArrayObjectAtIndex<span style="color: #002200;">&#40;</span>array, ii<span style="color: #002200;">&#41;</span>;
        <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Index: %d - %s<span style="color: #2400d9;">\n</span>&quot;</span>, ii, buffer<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p><strong>Download:</strong></p>
<p><a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/CArray.h">CArray.h</a></p>
<p><a href="http://www.benreeves.co.uk/wp-content/uploads/2010/01/CArray.c">CArray.c</a></p>
<p><strong>Notes:</strong><br />
The following test  function usually reports about 5x faster than NSMutableArray which I think is a credit to how efficient the Objective C library and messaging system really is considering all the things your missing out on (exceptions, null pointers etc)</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">void</span> CArrayTestRoutine<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
&nbsp;
    CArray <span style="color: #002200;">*</span> array <span style="color: #002200;">=</span> CArrayInit<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
    NSTimeInterval start <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDate</span> date<span style="color: #002200;">&#93;</span> timeIntervalSince1970<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> test;
&nbsp;
    <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> ii <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; ii <span style="color: #002200;">&amp;</span>lt; <span style="color: #2400d9;">10000000</span>; <span style="color: #002200;">++</span>ii<span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        CArrayAdd<span style="color: #002200;">&#40;</span>array, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;test&quot;</span><span style="color: #002200;">&#41;</span>;
        test <span style="color: #002200;">=</span> CArrayObjectAtIndex<span style="color: #002200;">&#40;</span>array, CArrayCount<span style="color: #002200;">&#40;</span>array<span style="color: #002200;">&#41;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
     CArrayRemoveObjectAtIndex<span style="color: #002200;">&#40;</span>array, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>;
&nbsp;
     NSTimeInterval end <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDate</span> date<span style="color: #002200;">&#93;</span> timeIntervalSince1970<span style="color: #002200;">&#93;</span>;
     <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;CArray 100,000,000 Elements took %fs<span style="color: #2400d9;">\n</span>&quot;</span>, end<span style="color: #002200;">-</span>start<span style="color: #002200;">&#41;</span>;
&nbsp;
     <span style="color: #400080;">NSMutableArray</span> <span style="color: #002200;">*</span> nsarray <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableArray</span> alloc<span style="color: #002200;">&#93;</span> initWithCapacity<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
     start <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDate</span> date<span style="color: #002200;">&#93;</span> timeIntervalSince1970<span style="color: #002200;">&#93;</span>;
     <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span> <span style="color: #a61390;">string</span>;
&nbsp;
     <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> ii <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; ii <span style="color: #002200;">&amp;</span>lt; <span style="color: #2400d9;">10000000</span>; <span style="color: #002200;">++</span>ii<span style="color: #002200;">&#41;</span>
    <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>nsarray addObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;test&quot;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">string</span> <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>nsarray objectAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>nsarray count<span style="color: #002200;">&#93;</span><span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #002200;">&#91;</span>nsarray removeObjectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
&nbsp;
     end <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDate</span> date<span style="color: #002200;">&#93;</span> timeIntervalSince1970<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>nsarray release<span style="color: #002200;">&#93;</span>;
     <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;NSMutableArray 100,000,000 Elements took %fs<span style="color: #2400d9;">\n</span>&quot;</span>, end<span style="color: #002200;">-</span>start<span style="color: #002200;">&#41;</span>;
&nbsp;
     <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;%s<span style="color: #2400d9;">\n</span>&quot;</span>, <span style="color: #002200;">&#91;</span><span style="color: #a61390;">string</span> UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
     <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;%s<span style="color: #2400d9;">\n</span>&quot;</span>, <span style="color: #002200;">&#91;</span>test UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
     CArrayDestroy<span style="color: #002200;">&#40;</span>array<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/dynamic-arrays-with-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iVersion</title>
		<link>http://benreeves.co.uk/75/</link>
		<comments>http://benreeves.co.uk/75/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 17:06:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[svn client]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=75</guid>
		<description><![CDATA[iVersion is a SVN client for the iphone 3G and ipod touch.
iVersion uses the open source subversion 1.6 client library, written in plain C, with an Objective C wrapper for simpler interfacing with the Objective C UI. Using an objective C Wrapper the client can easily be abstracted to work with other version control protocols. In [...]]]></description>
			<content:encoded><![CDATA[<p><strong>iVersion is a SVN client for the iphone 3G and ipod touch.</strong></p>
<p>iVersion uses the open source <a rel="self" href="http://subversion.tigris.org/">subversion 1.6 </a>client library, written in plain C, with an Objective C wrapper for simpler interfacing with the Objective C UI. Using an objective C Wrapper the client can easily be abstracted to work with other version control protocols. In the future <a rel="self" href="http://git-scm.com/">git</a>, <a rel="self" href="http://www.selenic.com/mercurial/wiki/">mercurial</a>and <a rel="self" href="http://bazaar-vcs.org/en/">bazaar</a> support maybe included.</p>
<h2>Features</h2>
<ul>
<li>Multi-threaded non-locking ui</li>
<li>OpenSSL support for https:// and svn+ssh:// connections</li>
<li>svn commands: list, info, cat,</li>
<li>Browse Directories</li>
<li>View Commit Logs</li>
<li>View file Info</li>
<li>Bookmarks, History &amp; Directory Cache through NSUserDefaults</li>
</ul>
<p><em>** Commit Support<br />
Subversion does not allow commiting of a single file without a working copy of the previous directory. A work around for this has been found and commit support should be available in a future version.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/75/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mosaico Web Gallery</title>
		<link>http://benreeves.co.uk/mosaico-web-gallery/</link>
		<comments>http://benreeves.co.uk/mosaico-web-gallery/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 12:23:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[image gallery]]></category>
		<category><![CDATA[mosaico]]></category>
		<category><![CDATA[web gallery]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=23</guid>
		<description><![CDATA[Specification:
 Desktop Application for Mac OSX 10.5
1. Loads an XML file;
2. Presents the XML data in an a table that can be sorted by each column;
3. Enables custom views of data, i.e., show all columns or only some;
4. Exports updated information back into the XML format;
5. Has an &#8220;FTP Widget&#8221; that can upload images to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Specification:<br />
</strong> Desktop Application for Mac OSX 10.5</p>
<p>1. Loads an XML file;<br />
2. Presents the XML data in an a table that can be sorted by each column;<br />
3. Enables custom views of data, i.e., show all columns or only some;<br />
4. Exports updated information back into the XML format;<br />
5. Has an &#8220;FTP Widget&#8221; that can upload images to a server.</p>
<p><strong>Solution:<br />
</strong> As per the clients specification the application was written using primarily Objective C, with Xcode as the development IDE. The UI is designed to be powerful and customizable. Profiles can be created to customize the view of the XML data. The Main window is split between an image view and a table view, which the user can adjust and hide if necessary, which is smoothly animated. Side drawers are used to display additional Options to the user.</p>
<p>XML parsing is handled using Cocoa’s bundled <span style="color: #ff3399;">NSXMLParser</span> using the format supplied by the client. The XML file can be imported, searched and exported using a tabular style layout. Fields can be edited, copied or deleted using single or multiple selections. The XML file can be uploaded to the site from within the app using <span style="color: #ff3399;">NSURLConnection</span> and http post.</p>
<p>Initially the possibility of using an existing Objective C Ftp library, such as <a title="Connection kit FTP framework" href="http://opensource.utr-software.com/connection/" target="_blank" class="broken_link">Connection kit</a> was explored, as well as the possibility of interfacing directly with an existing Mac ftp client such as Cyberduck. However the final solution was to write a lightweight ftp client using C Sockets with an Objective C API wrapper. The result is the user can quickly and easily upload and download images directly from the program, without any external dependancies.</p>
<p>Mosiaco has been tested throughly with <a title="Xcode IDE" href="http://developer.apple.com/technology/tools.html" target="_blank">Xcode’s Leaks</a> and <a title="GNU Debugger" href="http://www.gnu.org/software/gdb/" target="_blank">GNU gdb</a> and is stable and leak free without garbage collection.</p>
<p><em><span style="color: #808080;">“ zootreeves was exactly the kind of provider I was looking for in this collaboration: he knew exactly how to take my vision for the app and make it a reality. In addition, he always brought alternative solutions and new ideas to the table. The final product is above and beyond what I had hoped to create. He was a thorough pleasure to work with and I would highly recommend him to anyone looking for a Mac OS X app developer. Timothy Allen President &amp; Creative Director Hypergolica, Inc. www.hypergolica.net”</span></em></p>
<p>For more information regarding the Mosaico web gallery desktop software or if you are interested in finding an all in one solution for your online web gallery hosting please contact <a href="http://www.mosaico-webgallery.com/">Mosaico</a> or <a href="http://www.hypergolica.net/">Hypergolica</a></p>

<div class="ngg-galleryoverview" id="ngg-gallery-2-23">

	<!-- Slideshow link -->
	<div class="slideshowlink">
		<a class="slideshowlink" href="http://benreeves.co.uk/mosaico-web-gallery/?show=slide">
			[Show as slideshow]		</a>
	</div>

	
	<!-- Thumbnails -->
		
	<div id="ngg-image-23" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/page5-1000-full.jpg" title=" "  >
								<img title="page5-1000-full" alt="page5-1000-full" src="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/thumbs/thumbs_page5-1000-full.jpg" width="96" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-24" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/page5-1001-full.jpg" title=" "  >
								<img title="page5-1001-full" alt="page5-1001-full" src="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/thumbs/thumbs_page5-1001-full.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-25" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/page5-1002-full.jpg" title=" "  >
								<img title="page5-1002-full" alt="page5-1002-full" src="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/thumbs/thumbs_page5-1002-full.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-26" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/page5-1003-full.jpg" title=" "  >
								<img title="page5-1003-full" alt="page5-1003-full" src="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/thumbs/thumbs_page5-1003-full.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-27" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/page5-1004-full.jpg" title=" "  >
								<img title="page5-1004-full" alt="page5-1004-full" src="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/thumbs/thumbs_page5-1004-full.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-28" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/page5-1005-full.jpg" title=" "  >
								<img title="page5-1005-full" alt="page5-1005-full" src="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/thumbs/thumbs_page5-1005-full.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-29" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/page5-1006-full.jpg" title=" "  >
								<img title="page5-1006-full" alt="page5-1006-full" src="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/thumbs/thumbs_page5-1006-full.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-30" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/page5-1007-full.jpg" title=" "  >
								<img title="page5-1007-full" alt="page5-1007-full" src="http://benreeves.co.uk/wp-content/gallery/mosaico-web-gallery-screenshots/thumbs/thumbs_page5-1007-full.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


]]></content:encoded>
			<wfw:commentRss>http://benreeves.co.uk/mosaico-web-gallery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
