<?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>fullstop.</title>
	<atom:link href="http://www.russellj.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.russellj.co.uk/blog</link>
	<description>programming, &#38;c. by Russell Joyce</description>
	<lastBuildDate>Sat, 09 Jul 2011 18:39:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>NSURLConnection in a Background Thread</title>
		<link>http://www.russellj.co.uk/blog/2011/07/09/nsurlconnection-in-a-background-thread/</link>
		<comments>http://www.russellj.co.uk/blog/2011/07/09/nsurlconnection-in-a-background-thread/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 18:00:24 +0000</pubDate>
		<dc:creator>Russell</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[CATiledLayer]]></category>
		<category><![CDATA[CFRunLoop]]></category>
		<category><![CDATA[NSURLConnection]]></category>

		<guid isPermaLink="false">http://www.russellj.co.uk/blog/?p=20</guid>
		<description><![CDATA[Just a quick post to highlight a little issue I was having getting tiles to load from the internet for the campus map in the YUSU iPhone app. Basically, getting an NSURLConnection to load something asynchronously in a background thread requires a bit of extra work than running it in the main thread (which I needed to [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick post to highlight a little issue I was having getting tiles to load from the internet for the campus map in the YUSU iPhone app.</p>
<p>Basically, getting an <code class="codecolorer objc mac-classic"><span class="objc"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/"><span style="color: #400080;">NSURLConnection</span></a></span></code> to load something asynchronously in a background thread requires a bit of extra work than running it in the main thread (which I needed to do as the <code class="codecolorer objc mac-classic"><span class="objc">CATiledLayer</span></code> I use loads tiles in the background).</p>
<p>The problem arises from the background thread stopping before the <code class="codecolorer objc mac-classic"><span class="objc"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/"><span style="color: #400080;">NSURLConnection</span></a></span></code> actually gets any response. Luckily it's pretty easy to force a thread/run loop to keep running with <code class="codecolorer objc mac-classic"><span class="objc">CFRunLoopRun<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span></span></code>. Just don't forget to stop it when you're done with <code class="codecolorer objc mac-classic"><span class="objc">CFRunLoopStop<span style="color: #002200;">&#40;</span>CFRunLoopGetCurrent<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span></span></code>.</p>
<p>Here's some sample code:</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>startLoadWithURL<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span style="color: #400080;">NSURL</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>url <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/"><span style="color: #400080;">NSURLRequest</span></a> <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/"><span style="color: #400080;">NSURLRequest</span></a> requestWithURL<span style="color: #002200;">:</span>url<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/"><span style="color: #400080;">NSURLConnection</span></a> connectionWithRequest<span style="color: #002200;">:</span>request delegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; CFRunLoopRun<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connectionDidFinishLoading<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/"><span style="color: #400080;">NSURLConnection</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Do something with the finished connection</span><br />
&nbsp; &nbsp; CFRunLoopStop<span style="color: #002200;">&#40;</span>CFRunLoopGetCurrent<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/"><span style="color: #400080;">NSURLConnection</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection didFailWithError<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/"><span style="color: #400080;">NSError</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>error <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Handle the error</span><br />
&nbsp; &nbsp; CFRunLoopStop<span style="color: #002200;">&#40;</span>CFRunLoopGetCurrent<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.russellj.co.uk/blog/2011/07/09/nsurlconnection-in-a-background-thread/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;Hello, world&#8221;</title>
		<link>http://www.russellj.co.uk/blog/2011/07/09/hello-world-2/</link>
		<comments>http://www.russellj.co.uk/blog/2011/07/09/hello-world-2/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 14:01:47 +0000</pubDate>
		<dc:creator>Russell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.russellj.co.uk/blog/?p=14</guid>
		<description><![CDATA[Today I thought it was probably about time to start using this blog, which I set up nearly a year ago now, to actually post some things. I imagine they'll mostly be about programming - mainly trying to deal with problems I come across and can't find any other help about, although maybe some little [...]]]></description>
			<content:encoded><![CDATA[<p>Today I thought it was probably about time to start using this blog, which I set up nearly a year ago now, to actually post some things.</p>
<p>I imagine they'll mostly be about programming - mainly trying to deal with problems I come across and can't find any other help about, although maybe some little tutorials too. We'll see.</p>
<p>Anyway, if anyone's actually reading this, thanks and see you soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.russellj.co.uk/blog/2011/07/09/hello-world-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

