<?xml version="1.0" encoding="UTF-8"?>
<rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>João Prado Maia's Weblog</title>
	<atom:link href="http://pessoal.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://pessoal.org/blog</link>
	<description />
	<pubDate>Sat, 30 May 2009 04:00:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rasmus Lerdorf in Houston!</title>
		<link>http://feedproxy.google.com/~r/joaopmaia/~3/iFnmTdd4mxw/</link>
		<comments>http://pessoal.org/blog/2009/05/29/rasmus-lerdorf-in-houston/#comments</comments>
		<pubDate>Sat, 30 May 2009 04:00:11 +0000</pubDate>
		<dc:creator>jpm</dc:creator>
		
		<category><![CDATA[Houston PHP/MySQL Meetup]]></category>

		<guid isPermaLink="false">http://pessoal.org/blog/?p=208</guid>
		<description><![CDATA[Rasmus Lerdorf, creator of the PHP language, will be in Houston in June and graciously volunteered to do a presentation to our group! Sorry about the last minute modification, but we will need to move our meeting from our usual date/time to Wednesday June 10th at 6:00pm. The presentation details below from Rasmus himself:
Architecture, Performance, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://lerdorf.com/">Rasmus Lerdorf</a>, creator of the PHP language, will be in Houston in June and graciously volunteered to do a presentation to our group! Sorry about the last minute modification, but we will need to move our meeting from our usual date/time to Wednesday June 10th at 6:00pm. The presentation details below from Rasmus himself:</p>
<blockquote><p>Architecture, Performance, Optimization and Security.</p>
<p>I take a look at the performance of some popular PHP applications and go<br />
through and show the common mistakes people make and show how much of a<br />
difference just a little bit of optimization makes.</p>
<p>Then, if there is still time and interest I&#8217;ll explain the current state<br />
of XSS on the Web with some live examples of XSS issues on some local<br />
sites.  I usually like to have 2-3 hours, but I can squeeze it into less.
</p></blockquote>
<p>I hope to see you all here for this great opportunity! <a href="http://php.meetup.com/121/calendar/10364742/">You can RSVP here.</a></p>
<p>&#8211;Joao</p>
<img src="http://feeds.feedburner.com/~r/joaopmaia/~4/iFnmTdd4mxw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pessoal.org/blog/2009/05/29/rasmus-lerdorf-in-houston/feed/</wfw:commentRss>
		<feedburner:origLink>http://pessoal.org/blog/2009/05/29/rasmus-lerdorf-in-houston/</feedburner:origLink></item>
		<item>
		<title>Customizing the background/border colors of a UITableView (grouped style)</title>
		<link>http://feedproxy.google.com/~r/joaopmaia/~3/8G_EPMYlp14/</link>
		<comments>http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 02:51:19 +0000</pubDate>
		<dc:creator>jpm</dc:creator>
		
		<category><![CDATA[Objective-C]]></category>

		<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://pessoal.org/blog/?p=149</guid>
		<description><![CDATA[Customizing the background color of a UITableView is somewhat easy, but only if you use the plain style. If you use the grouped style of a table view, it starts to get way more complex. There are no easy ways to quickly set a property for the border color and the background color of the [...]]]></description>
			<content:encoded><![CDATA[<p>Customizing the background color of a UITableView is somewhat easy, but only if you use the plain style. If you use the grouped style of a table view, it starts to get way more complex. There are no easy ways to quickly set a property for the border color and the background color of the whole table view cell. Well, there are, but if you try to change some of these values and try to use the grouped style, it will look completely wrong.</p>
<p>Below you have a proper grouped table view using the standard Apple theme:</p>
<p><a href="http://pessoal.org/blog/wp-content/uploads/2009/02/standard.png"><img src="http://pessoal.org/blog/wp-content/uploads/2009/02/standard-200x300.png" alt="Standard style" title="Standard style" width="200" height="300" class="alignleft size-medium wp-image-191" /></a></p>
<p>Looks pretty good, and it is also very simple to build that in objective-c. Assuming you use Interface Builder for your UI work, just set the table view as a &#8220;grouped&#8221;, and then set the title property of each cell, like this:</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>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell&quot;</span>;
&nbsp;
    UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectZero reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    cell.accessoryType <span style="color: #002200;">=</span> UITableViewCellAccessoryDisclosureIndicator;
&nbsp;
    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>list <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;First&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Second&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Third&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    cell.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>list objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>So now let&#8217;s try something tricky and simply change the backgroundColor property of cell.contentView, as that works fine when dealing with &#8220;plain&#8221; style table views. The code would be just a bit different:</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>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell&quot;</span>;
&nbsp;
    UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectZero reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    cell.accessoryType <span style="color: #002200;">=</span> UITableViewCellAccessoryDisclosureIndicator;
&nbsp;
    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>list <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;First&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Second&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Third&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    cell.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>list objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;
&nbsp;
    cell.contentView.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor redColor<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>And this is what it looks like:</p>
<p><a href="http://pessoal.org/blog/wp-content/uploads/2009/02/broken.png"><img src="http://pessoal.org/blog/wp-content/uploads/2009/02/broken-200x300.png" alt="Broken results" title="Broken results" width="200" height="300" class="alignleft size-medium wp-image-190" /></a></p>
<p>At first I thought about changing cell.backgroundView, but that doesn&#8217;t work. So you can see that changing the contentView doesn&#8217;t work either, and it actually breaks a bunch of things:</p>
<ul>
<li>No rounded corners on the left side of the table view anymore</li>
<li>The background color on the disclosure image is still set to white</li>
<li>How do we change the border color anyway?</li>
</ul>
<p>So after researching this problem for a while, and asking around for a solution, it seemed like there was no way to customize this stuff without a lot of manual work. Indeed that was the case, but <a href="http://www.michaelakers.net/">Mike Akers</a> (another <a href="http://stackoverflow.com/questions/tagged/iphone">StackOverflow.com</a> member) posted the source code to a solution that he came up with, and that works very well so far. <a href="http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view">You can see his source code here</a> for a custom background view with a border.</p>
<p>Here it is a modified version of my code to use his class:</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>UITableViewCell <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UITableView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>tableView cellForRowAtIndexPath<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSIndexPath</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>indexPath <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>CellIdentifier <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Cell&quot;</span>;
&nbsp;
    UITableViewCell <span style="color: #002200;">*</span>cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>tableView dequeueReusableCellWithIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>cell <span style="color: #002200;">==</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        cell <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITableViewCell alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectZero reuseIdentifier<span style="color: #002200;">:</span>CellIdentifier<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
    cell.accessoryType <span style="color: #002200;">=</span> UITableViewCellAccessoryDisclosureIndicator;
&nbsp;
    UILabel <span style="color: #002200;">*</span>label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;
    label.font <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont boldSystemFontOfSize<span style="color: #002200;">:</span>16.0f<span style="color: #002200;">&#93;</span>;
    label.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>40.0f, 10.0f, 220.0f, 22.0f<span style="color: #002200;">&#41;</span>;
    label.textColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor whiteColor<span style="color: #002200;">&#93;</span>;
    label.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>;
    label.opaque <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
&nbsp;
    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>list <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSArray</span> arrayWithObjects<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;First&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Second&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Third&quot;</span>, <span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    label.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>list objectAtIndex<span style="color: #002200;">:</span>indexPath.row<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>cell.contentView addSubview<span style="color: #002200;">:</span>label<span style="color: #002200;">&#93;</span>;
&nbsp;
    CustomCellBackgroundView <span style="color: #002200;">*</span>bgView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>CustomCellBackgroundView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectZero<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>indexPath.row <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        bgView.position <span style="color: #002200;">=</span> CustomCellBackgroundViewPositionTop;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>indexPath.row <span style="color: #002200;">==</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        bgView.position <span style="color: #002200;">=</span> CustomCellBackgroundViewPositionMiddle;
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
        bgView.position <span style="color: #002200;">=</span> CustomCellBackgroundViewPositionBottom;
    <span style="color: #002200;">&#125;</span>
    cell.backgroundView <span style="color: #002200;">=</span> bgView;
    cell.accessoryView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImageView alloc<span style="color: #002200;">&#93;</span> initWithImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;more_arrow.png&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> cell;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>And the resulting interface:</p>
<p><a href="http://pessoal.org/blog/wp-content/uploads/2009/02/proper.png"><img src="http://pessoal.org/blog/wp-content/uploads/2009/02/proper-200x300.png" alt="Proper background and border colors" title="Proper background and border colors" width="200" height="300" class="alignleft size-medium wp-image-198" /></a></p>
<p>Ugly colors, but you get the idea. The code is also way more complex than before, but at least it&#8217;s possible to customize the background and border colors of a table view cell. This is more or less what we use on <a href="http://impleo.net/kneecap.html">Knee Cap</a>, our iPhone app that handles day to day money loans. This is what our custom table view looks like:</p>
<p><a href="http://pessoal.org/blog/wp-content/uploads/2009/02/primary.jpg"><img src="http://pessoal.org/blog/wp-content/uploads/2009/02/primary-208x300.jpg" alt="Knee Cap" title="Knee Cap" width="208" height="300" class="alignleft size-medium wp-image-170" /></a></p>
<img src="http://feeds.feedburner.com/~r/joaopmaia/~4/8G_EPMYlp14" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/feed/</wfw:commentRss>
		<feedburner:origLink>http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/</feedburner:origLink></item>
		<item>
		<title>iPhone SDK: Setting up a SQLite database before first use</title>
		<link>http://feedproxy.google.com/~r/joaopmaia/~3/W8n6L79vx0Y/</link>
		<comments>http://pessoal.org/blog/2009/02/24/iphone-sdk-setting-up-a-sqlite-database-before-first-use/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 03:34:53 +0000</pubDate>
		<dc:creator>jpm</dc:creator>
		
		<category><![CDATA[Objective-C]]></category>

		<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://pessoal.org/blog/?p=183</guid>
		<description><![CDATA[It&#8217;s quite common to use SQLite databases in iPhone apps to serve as the backend for your product. While there is a way to create the database file dynamically from your objective-c code, it&#8217;s way simpler to create it in your Mac development machine, add it to your Xcode project, and then simply write the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s quite common to use SQLite databases in iPhone apps to serve as the backend for your product. While there is a way to create the database file dynamically from your objective-c code, it&#8217;s way simpler to create it in your Mac development machine, add it to your Xcode project, and then simply write the code to copy the database file from your app bundle to your app&#8217;s document directory.</p>
<p>I use the following code in my projects to do just that:</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: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>copyDBToFinalPath <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>originalDBPath <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> pathForResource<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;database_filename_here&quot;</span> ofType<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;db&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>path <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
    <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>paths <span style="color: #002200;">=</span> NSSearchPathForDirectoriesInDomains<span style="color: #002200;">&#40;</span>NSDocumentDirectory, NSUserDomainMask, <span style="color: #a61390;">YES</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>appSupportDir <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>paths objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>appBundleName <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;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> infoDictionary<span style="color: #002200;">&#93;</span> objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;CFBundleName&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>dbNameDir <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@/%@&quot;</span>, appSupportDir, appBundleName<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSFileManager</span> <span style="color: #002200;">*</span>fileManager <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSFileManager</span> defaultManager<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">BOOL</span> isDir <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
    <span style="color: #a61390;">BOOL</span> dirExists <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>fileManager fileExistsAtPath<span style="color: #002200;">:</span>dbNameDir isDirectory<span style="color: #002200;">:&amp;</span>isDir<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>dbPath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@/database_filename_here.db&quot;</span>, dbNameDir<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>dirExists <span style="color: #002200;">&amp;&amp;</span> isDir<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">BOOL</span> dbExists <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>fileManager fileExistsAtPath<span style="color: #002200;">:</span>dbPath<span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>dbExists<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
            <span style="color: #a61390;">BOOL</span> success <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>fileManager copyItemAtPath<span style="color: #002200;">:</span>originalDBPath toPath<span style="color: #002200;">:</span>dbPath error<span style="color: #002200;">:&amp;</span>error<span style="color: #002200;">&#93;</span>;
            <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>success<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: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
                path <span style="color: #002200;">=</span> dbPath;
            <span style="color: #002200;">&#125;</span>
        <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
            path <span style="color: #002200;">=</span> dbPath;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>dirExists<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>error <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
        <span style="color: #a61390;">BOOL</span> success <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>fileManager createDirectoryAtPath<span style="color: #002200;">:</span>dbNameDir attributes<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>success<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;failed to create dir&quot;</span><span style="color: #002200;">&#41;</span>;
        <span style="color: #002200;">&#125;</span>
        success <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>fileManager copyItemAtPath<span style="color: #002200;">:</span>originalDBPath toPath<span style="color: #002200;">:</span>dbPath error<span style="color: #002200;">:&amp;</span>error<span style="color: #002200;">&#93;</span>;
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>success<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: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
            path <span style="color: #002200;">=</span> dbPath;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
    <span style="color: #a61390;">return</span> path;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>I use that function like so:</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>applicationDidFinishLaunching<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIApplication <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>application <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>dbPath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self copyDBToFinalPath<span style="color: #002200;">&#93;</span>;
    self.db <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>FMDatabase databaseWithPath<span style="color: #002200;">:</span>dbPath<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>self.db open<span style="color: #002200;">&#93;</span><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;Could not open database.&quot;</span><span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
    <span style="color: #11740a; font-style: italic;">//[self.db setTraceExecution:YES];</span>
    <span style="color: #11740a; font-style: italic;">//[self.db setLogsErrors:YES];</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// ...</span>
    <span style="color: #11740a; font-style: italic;">// rest of my code here</span>
    <span style="color: #11740a; font-style: italic;">// ...</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>To create that original SQLite database file, just use the standard &#8220;sqlite3&#8243; command found in Mac OS X like so:</p>
<pre>
$ sqlite3 database_filename_here.db
SQLite version 3.4.0
Enter ".help" for instructions
sqlite> .read ./schema.sql
</pre>
<p>The &#8220;schema.sql&#8221; file is where I store my table definitions, and standard inserts.</p>
<img src="http://feeds.feedburner.com/~r/joaopmaia/~4/W8n6L79vx0Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pessoal.org/blog/2009/02/24/iphone-sdk-setting-up-a-sqlite-database-before-first-use/feed/</wfw:commentRss>
		<feedburner:origLink>http://pessoal.org/blog/2009/02/24/iphone-sdk-setting-up-a-sqlite-database-before-first-use/</feedburner:origLink></item>
		<item>
		<title>My iPhone app is finally live!</title>
		<link>http://feedproxy.google.com/~r/joaopmaia/~3/yluPS7mmDe4/</link>
		<comments>http://pessoal.org/blog/2009/02/16/my-iphone-app-is-finally-live/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 02:50:09 +0000</pubDate>
		<dc:creator>jpm</dc:creator>
		
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://pessoal.org/blog/?p=168</guid>
		<description><![CDATA[ Knee Cap, the iPhone app I have been working on for the past few weeks, has been approved by Apple and is finally for sale in the App Store.
I&#8217;m looking forward to see the reception it gets after all the hard work I put into it.

]]></description>
			<content:encoded><![CDATA[<p><img src="http://pessoal.org/blog/wp-content/uploads/2009/02/primary-208x300.jpg" alt="primary" title="primary" width="208" height="300" style="float: left; margin-right: 10px;" /> Knee Cap, the iPhone app I have been working on for the past few weeks, has been approved by Apple and is <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=303323584&#038;mt=8">finally for sale in the App Store</a>.</p>
<p>I&#8217;m looking forward to see the reception it gets after all the hard work I put into it.</p>
<div style="clear: both;"></div>
<img src="http://feeds.feedburner.com/~r/joaopmaia/~4/yluPS7mmDe4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pessoal.org/blog/2009/02/16/my-iphone-app-is-finally-live/feed/</wfw:commentRss>
		<feedburner:origLink>http://pessoal.org/blog/2009/02/16/my-iphone-app-is-finally-live/</feedburner:origLink></item>
		<item>
		<title>iPhone SDK: formatting a numeric value with NSNumberFormatter</title>
		<link>http://feedproxy.google.com/~r/joaopmaia/~3/IZaXthfZqQw/</link>
		<comments>http://pessoal.org/blog/2009/02/09/iphone-sdk-formatting-a-numeric-value-with-nsnumberformatter/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 04:16:27 +0000</pubDate>
		<dc:creator>jpm</dc:creator>
		
		<category><![CDATA[Objective-C]]></category>

		<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://pessoal.org/blog/?p=162</guid>
		<description><![CDATA[While working on an application that downloads a PDF document into a UIWebView, I wrote some code to display a progress bar while the user waits for the file to be downloaded. It turned out to be very simple to do this, but I hit a snag after trying to also display the amount of [...]]]></description>
			<content:encoded><![CDATA[<p>While working on an application that downloads a PDF document into a UIWebView, I wrote some code to display a progress bar while the user waits for the file to be downloaded. It turned out to be very simple to do this, but I hit a snag after trying to also display the amount of bytes that has been retrieved so far. Something like &#8220;0.45 Mb of 4.56 Mb&#8221;.</p>
<p>Problem was that by default NSNumberFormatter displays number with 3 decimal places, and I needed to customize that a bit, so I could get only 2 decimal places, and always a number before the decimal separator. For instance, getting &#8220;0.45 Mb&#8221; instead of just &#8220;.45 Mb&#8221;. The magical solution was the setPositiveFormat method, which allows the developer to specify these parameters.</p>
<p>Here&#8217;s the code that I ended up using, and it works great:</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>createProgressionAlertWithMessage<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>message <span style="color: #002200;">&#123;</span>
    progressAlert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span> initWithTitle<span style="color: #002200;">:</span>message message<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Please wait...&quot;</span> delegate<span style="color: #002200;">:</span>self cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> otherButtonTitles<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">// Create the progress bar and add it to the alert</span>
    progressView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIProgressView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>30.0f, 80.0f, 225.0f, 90.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>progressAlert addSubview<span style="color: #002200;">:</span>progressView<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>progressView setProgressViewStyle<span style="color: #002200;">:</span>UIProgressViewStyleBar<span style="color: #002200;">&#93;</span>;
&nbsp;
    UILabel <span style="color: #002200;">*</span>label <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>90.0f, 90.0f, 225.0f, 40.0f<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
    label.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>;
    label.textColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor whiteColor<span style="color: #002200;">&#93;</span>;
    label.font <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIFont systemFontOfSize<span style="color: #002200;">:</span>12.0f<span style="color: #002200;">&#93;</span>;
    label.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span>;
    label.tag <span style="color: #002200;">=</span> kDownloadCounterTag;
    <span style="color: #002200;">&#91;</span>progressAlert addSubview<span style="color: #002200;">:</span>label<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>progressAlert show<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>progressAlert release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>That&#8217;s the method that creates the UIAlertView that will hold the progress bar, and also the UIProgressView itself to display the progress of the download. I added an extra label in there to finally display the actual bytes of the file as it is being streamed over.</p>
<p>For the actual download I&#8217;m using NSURLConnection so I can download the file asynchronously, and receive information while the download is progressing.</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>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>file <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://domain.com/download?id=%@&quot;</span>, self.docID<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>fileURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span>file<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSURLRequest</span> <span style="color: #002200;">*</span>req <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLRequest</span> requestWithURL<span style="color: #002200;">:</span>fileURL<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span>conn <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLConnection</span> connectionWithRequest<span style="color: #002200;">:</span>req delegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>self createProgressionAlertWithMessage<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Downloading document&quot;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection didReceiveResponse<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLResponse</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>response <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>self.fileData setLength<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;
    self.totalFileSize <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithLongLong<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>response expectedContentLength<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection didReceiveData<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>data <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>self.fileData appendData<span style="color: #002200;">:</span>data<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>resourceLength <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithUnsignedInteger<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self.fileData length<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>progress <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithFloat<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>resourceLength floatValue<span style="color: #002200;">&#93;</span> <span style="color: #002200;">/</span> <span style="color: #002200;">&#91;</span>self.totalFileSize floatValue<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
    progressView.progress <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>progress floatValue<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">const</span> <span style="color: #a61390;">unsigned</span> <span style="color: #a61390;">int</span> bytes <span style="color: #002200;">=</span> <span style="color: #2400d9;">1024</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">1024</span>;
    UILabel <span style="color: #002200;">*</span>label <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>UILabel <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>progressAlert viewWithTag<span style="color: #002200;">:</span>kDownloadCounterTag<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSNumberFormatter</span> <span style="color: #002200;">*</span>formatter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumberFormatter</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>formatter setNumberStyle<span style="color: #002200;">:</span>NSNumberFormatterDecimalStyle<span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>formatter setPositiveFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;##0.00&quot;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>partial <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithFloat<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>resourceLength floatValue<span style="color: #002200;">&#93;</span> <span style="color: #002200;">/</span> bytes<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>total <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithFloat<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self.totalFileSize floatValue<span style="color: #002200;">&#93;</span> <span style="color: #002200;">/</span> bytes<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
    label.text <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@ MB of %@ MB&quot;</span>, <span style="color: #002200;">&#91;</span>formatter stringFromNumber<span style="color: #002200;">:</span>partial<span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&#91;</span>formatter stringFromNumber<span style="color: #002200;">:</span>total<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>formatter release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection didFailWithError<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>error <span style="color: #002200;">&#123;</span>
    <span style="color: #002200;">&#91;</span>progressAlert dismissWithClickedButtonIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span> animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>I&#8217;m hoping this is useful to someone else. Let me know if there&#8217;s a better to do some of the things I&#8217;m doing here.</p>
<img src="http://feeds.feedburner.com/~r/joaopmaia/~4/IZaXthfZqQw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pessoal.org/blog/2009/02/09/iphone-sdk-formatting-a-numeric-value-with-nsnumberformatter/feed/</wfw:commentRss>
		<feedburner:origLink>http://pessoal.org/blog/2009/02/09/iphone-sdk-formatting-a-numeric-value-with-nsnumberformatter/</feedburner:origLink></item>
	</channel>
</rss>
