<?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>Lee Falin &#187; iOS Programming</title>
	<atom:link href="http://leefalin.com/blog/category/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://leefalin.com/blog</link>
	<description>A Legend In His Own Mind</description>
	<lastBuildDate>Mon, 10 Oct 2011 18:41:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>LDS Mastery for iOS</title>
		<link>http://leefalin.com/blog/2011/08/17/lds-mastery-for-ios/</link>
		<comments>http://leefalin.com/blog/2011/08/17/lds-mastery-for-ios/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 18:03:23 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=504</guid>
		<description><![CDATA[Just in time for seminary, my new scripture mastery app for iOS is now available in the app store. LDS Mastery helps you to memorize all 100 LDS Scripture Mastery scriptures for seminary using a variety of games. You can even share your progress on Twitter and Facebook. Get it today for only $0.99 and start [...]]]></description>
			<content:encoded><![CDATA[<p>Just in time for seminary, my new <a title="LDS Mastery for iOS" href="http://leefalin.com/projects/LDSMastery/">scripture mastery app</a> for iOS is now available in the <a title="App Store link" href="http://itunes.apple.com/us/app/lds-mastery/id456438121?mt=8">app store</a>.</p>
<p>LDS Mastery helps you to memorize all 100 LDS Scripture Mastery scriptures for seminary using a variety of games. You can even share your progress on Twitter and Facebook.</p>
<p><a href="http://leefalin.com/blog/wp-content/uploads/2011/08/ss3.png"><img class="alignnone size-full wp-image-505" style="margin: 5px; border: 1px solid black;" title="LDS Mastery Screenshot" src="http://leefalin.com/blog/wp-content/uploads/2011/08/ss3.png" alt="LDS Mastery Screenshot" width="320" height="480" /></a></p>
<p><a title="App Store Link" href="http://itunes.apple.com/us/app/lds-mastery/id456438121?mt=8">Get it today</a> for only $0.99 and start mastering your scriptures.</p>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2011/08/17/lds-mastery-for-ios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Scriptures 1.4.0 &#8211; Scripture Highlighting</title>
		<link>http://leefalin.com/blog/2011/04/19/the-scriptures-1-4-0-scripture-highlighting/</link>
		<comments>http://leefalin.com/blog/2011/04/19/the-scriptures-1-4-0-scripture-highlighting/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 13:40:18 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=357</guid>
		<description><![CDATA[The Scriptures for the iPhone and iPod Touch version 1.4.0 is now available for download from the App Store. You can read about the changes here. The big change in this version is scripture highlighting. Lots of people wanted the ability to highlight scriptures, but some people don&#8217;t care about that feature. So I&#8217;ve decided [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.leefalin.com/projects/scriptures/">The Scriptures for the iPhone and iPod Touch</a> version 1.4.0 is now available for download from the App Store. You can read about the changes <a href="http://leefalin.com/projects/scriptures/changelog.php">here</a>.</p>
<p><img src="http://leefalin.com/projects/scriptures/images/highlights/highlighter.png" alt="Scripture Highlighters" style="float:left; margin-right:20px;" width="160px" height="240px" />The big change in this version is <a href="http://leefalin.com/projects/scriptures/highlights.php">scripture highlighting</a>. Lots of people wanted the ability to highlight scriptures, but some people don&#8217;t care about that feature. So I&#8217;ve decided to make the feature available as an In-App Purchase for $0.99. If you want <a href="http://leefalin.com/projects/scriptures/highlights.php">scripture highlighting</a>, you can update to version 1.4.0 in the App Store and purchase the highlighters right in the application. </p>
<p>If you don&#8217;t care about scripture highlighting, you can ignore the new button and still benefit from the other bug fixes in version 1.4.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2011/04/19/the-scriptures-1-4-0-scripture-highlighting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BoredBeGone for the iPhone now available in the App Store</title>
		<link>http://leefalin.com/blog/2009/07/09/boredbegone-for-the-iphone-now-available-in-the-appstore/</link>
		<comments>http://leefalin.com/blog/2009/07/09/boredbegone-for-the-iphone-now-available-in-the-appstore/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 12:12:12 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=159</guid>
		<description><![CDATA[Never be bored again with BoredBeGone! Ever been sitting, waiting for someone or stuck at home and wondering what to do? BoredBeGone can help! Just answer a few simple questions and you&#8217;re on your way to excitement and adventure! (ok, maybe not so much adventure) Only 99 cents in the App Store. On the App [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.leefalin.com/projects/boredbegone/images/Icon.png" align="left" style="margin-right: 10px; margin-bottom: 5px">Never be bored again with <a href="http://www.leefalin.com/projects/BoredBeGone">BoredBeGone</a>!</p>
<p>Ever been sitting, waiting for someone or stuck at home and wondering what to do? BoredBeGone can help! Just answer a few simple questions and you&#8217;re on your way to excitement and adventure! (ok, maybe not so much adventure)</p>
<p>Only <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=321126060&#038;mt=8">99 cents in the App Store</a>.</p>
<h3>On the App Store Submission Process</h3>
<p>It took two tries to get BoredBeGone to the App Store. The first submission came back rejected for a bug. The bug only affected the functionality of the application in a certain condition that I forgot to test, even though I should have thought of it.</p>
<p>Lots of people complain about the amount of time to get through the review process, and there are some cases where maybe it should be faster, but I am thankful to the App Store review team and the time they take to test applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2009/07/09/boredbegone-for-the-iphone-now-available-in-the-appstore/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Scriptures for the iPhone at WWDC</title>
		<link>http://leefalin.com/blog/2009/06/15/the-scriptures-for-the-iphone-at-wwdc/</link>
		<comments>http://leefalin.com/blog/2009/06/15/the-scriptures-for-the-iphone-at-wwdc/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 01:46:42 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=158</guid>
		<description><![CDATA[Dave DeLong was nice enough to send me this picture of the icon for The Scriptures as seen on the App Store video wall at WWDC:]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/davedelong">Dave DeLong</a> was nice enough to send me this picture of the icon for The Scriptures as seen on the App Store video wall at WWDC:</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2009/06/scriptureswwdc.png" alt="scripturesWWDC.png" border="0" width="438" height="303" /></p>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2009/06/15/the-scriptures-for-the-iphone-at-wwdc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Future of the Scriptures for the iPhone</title>
		<link>http://leefalin.com/blog/2009/03/10/the-future-of-the-scriptures-for-the-iphone/</link>
		<comments>http://leefalin.com/blog/2009/03/10/the-future-of-the-scriptures-for-the-iphone/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 14:28:52 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=154</guid>
		<description><![CDATA[When I first purchased my iPhone, one of the first things that I wanted to do was install a portable copy of The Scriptures. There were lots of programs available for windows mobile and Palm devices for this, but as the iPhone as just starting to allow 3rd party development, there still wasn&#8217;t anything available [...]]]></description>
			<content:encoded><![CDATA[<p>When I first purchased my iPhone, one of the first things that I wanted to do was install a portable copy of <a href="http://scriptures.lds.org/">The Scriptures</a>. There were lots of programs available for windows mobile and Palm devices for this, but as the iPhone as just starting to allow 3rd party development, there still wasn&#8217;t anything available for it.</p>
<p>After releasing the application I started to receive lots of feedback and ideas about ways to make it better, and because of the importance of what the application represented to so many people, <a href="http://leefalin.com/projects/scriptures/changelog.php">I tried to incorporate</a> as many of the suggestions that I felt were appropriate and that I had time for given my limited availability.</p>
<p>As time went on there were two big items that lots of people wanted that were proving to be difficult:</p>
<ol>
<li>More content</li>
<p> People suggested everything from hymns to class manuals to old conference talks. The roadblock here of course is one of copyright. While it is okay to reproduce most of the materials in question for personal use, some of them (the hymns for example) have very tricky copyright issues involved. There is also the question of whether a 3rd party distributing the items for personal use was still ok.</p>
<li>Localizations</li>
<p>While the vast majority of the users were in the US (around 40,000), there were still several thousand outside of the US that were interested in having the Scriptures available in their own native languages. (Not to mention US residents whose native language isn&#8217;t English)</p>
<p>At first this seemed like it would be trivial because of the number of willing beta testers that I had who spoke foreign languages, and the standardized format the the Church uses for maintaing the Scriptures online in multiple languages. However there are lots of issues with parsing non-english text that come up when you&#8217;re trying to take a bunch of raw html data and convince it to conform to a normalized database structure. Because of the sacred nature of the Scriptures, this isn&#8217;t something that you would want to mess up.
</ol>
<p>These two obstacles not withstanding, I still felt this was an important project that I didn&#8217;t just want to give up on. Fortunately something happened a few weeks ago that provided a solution. I received an email from <a href="https://tech.lds.org/wiki/index.php/User:Welchtc">Tom Welch</a> of the LDS Tech community that contained an announcement saying that the Church was developing (among other things) its own iPhone Scriptures Application. I immediately contacted him and offered to donate all of the source code from my project and am happy that he accepted.</p>
<p>I don&#8217;t know how much (if any) of the actual code will be used in the final official church project. I am excited to see the Church continuing to embrace new technology as a method of spreading the Gospel as they have done <a href="http://maps.lds.org">so</a> <a href="http://www.youtube.com/MormonMessages">many</a> <a href="http://www.lds.org/ldsorg/v/index.jsp?vgnextoid=7fcee975d2a2b010VgnVCM1000004d82620aRCRD&#038;locale=0">times</a> before.</p>
<p>So this, sadly, marks the official end of my iPhone Scriptures Application project. The application will still remain available for download in its current form until the Church releases their own. Anyone wishing to assist with the project should look at the <a href="https://tech.lds.org/wiki/index.php/IPhone_Scriptures_Application">LDS Tech wiki pages</a> for the project and contact <a href="https://tech.lds.org/wiki/index.php/User:Welchtc">Tom Welch</a> via email.</p>
<p>Thanks for everyone who sent in words of encouragement and support. Also thanks to everyone that helped out with beta testing and offered to assist with localizations. This has been a wonderful experience and I have been blessed in so many ways because of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2009/03/10/the-future-of-the-scriptures-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The Scriptures 1.1.1</title>
		<link>http://leefalin.com/blog/2008/12/21/the-scriptures-111/</link>
		<comments>http://leefalin.com/blog/2008/12/21/the-scriptures-111/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 05:01:20 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=153</guid>
		<description><![CDATA[The Scriptures for the iPhone and iPod Touch version 1.1.1 is now available for download from the App Store. You can read about the changes here.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.leefalin.com/projects/scriptures/">The Scriptures for the iPhone and iPod Touch</a> version 1.1.1 is now available for download from the App Store. You can read about the changes <a href="http://leefalin.com/projects/scriptures/changelog.php">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2008/12/21/the-scriptures-111/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>iPhone SQLite Database Basics &#8211; Part 2</title>
		<link>http://leefalin.com/blog/2008/12/11/iphone-sqlite-database-basics-part-2/</link>
		<comments>http://leefalin.com/blog/2008/12/11/iphone-sqlite-database-basics-part-2/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 14:47:46 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=152</guid>
		<description><![CDATA[After writing the article on iPhone SQLite Database Basics, I received lots of followup questions and comments, some of which I will discuss here. SQLite Database Creation In my first article I wrote that the easiest way to work with SQLite databases on the mac was the SQLite extension for Firefox. Since then, my attention [...]]]></description>
			<content:encoded><![CDATA[<p>After writing the article on <a href="http://leefalin.com/blog/2008/10/02/iphone-sqlite-database-basics/">iPhone SQLite Database Basics</a>, I received lots of followup questions and comments, some of which I will discuss here.</p>
<h3>SQLite Database Creation</h3>
<p>In my first article I wrote that the easiest way to work with SQLite databases on the mac was the <a href="https://addons.mozilla.org/en-US/firefox/addon/5817">SQLite extension for Firefox</a>.</p>
<p>Since then, my attention has been brought to Menial&#8217;s <a href="http://menial.co.uk/software/base/">Base</a> application. This is the application that I now use for all of my SQLite work. It is super fast, and has an interface that is extremely easy to use. It also has a lot of nice touches that make it more Mac-like than using a Firefox extension. If you&#8217;re doing SQLite work on the Mac, I strongly recommend that you check it out.</p>
<h3>Making a Writable Copy of the Database</h3>
<p>In the <a href="http://leefalin.com/blog/2008/10/02/iphone-sqlite-database-basics/">first part</a> of this tutorial, I mentioned that if you needed to write to your database you needed to copy it to a location that you could write to.</p>
<p>A couple of people have asked how to do this. To answer that, I first want to talk a little bit about how to control SQLite access in Cocoa applications. There are really three ways to do this:</p>
<ol>
<li>Have DB access code in each class that needs it (bad)</li>
<li>Have you application delegate handle all DB access for you (better)</li>
<li>Use a singleton object for your DB access (best)</li>
</ol>
<p>For more about the tradeoffs between application delegate usage and singleton objects see <a href="http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html">this post from Cocoa with Love</a>.</p>
<p>If you are using the singleton pattern, then you can make a writable copy of your database in your <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_10.html">singleton object&#8217;s allocation</a> method, using something like this:</p>
<blockquote class="blockSource">
<ol>
<li><span class="sourceTextTwo">-(NSString*)createWriteableDB</li>
<li><span class="sourceTextTwo">{</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;// See if writeable database already exists</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;NSFileManager *fileManager = [NSFileManager defaultManager];</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;NSString *documentsDirectory = [paths objectAtIndex:0];</li>
<p><br/></p>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;NSString *readOnlyDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.databaseFileName];</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;NSString *writableDBPath = [[documentsDirectory stringByAppendingPathComponent:self.databaseFileName] retain];</li>
<p><br/></p>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;// First time install</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;if(![fileManager fileExistsAtPath:writableDBPath])</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(![fileManager copyItemAtPath:readOnlyDBPath toPath:writableDBPath error:&#038;self.lastError])</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSAssert1(0, @&#8221;Failed to create writable database file with message &#8216;%@&#8217;.&#8221;, [self.lastError localizedDescription]);</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return nil;</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;}</li>
<p><br/></p>
<li><span class="sourceTextTwo">&nbsp;&nbsp;&nbsp;&nbsp;return [writableDBPath autorelease];</li>
<li><span class="sourceTextTwo">}</li>
</ol>
</blockquote>
<p>A couple of important things to note here:</p>
<p>If you have a very large database and the things that you need to allow the user to update, (i.e. bookmarks, or annotations) are small in comparison, it may be better for you to have two databases files, one that contains the data that won&#8217;t change, and the other that contains the data used for annotations. This way you won&#8217;t have two large copies of the database on the user&#8217;s device.</p>
<p>This will of course have a large impact on your query design, and some database purists may be lining up to lynch me, but as I mentioned in the first article, there are some SQLite considerations that are unique to mobile devices like the iPhone.</p>
<p>Another thing to consider is versioning. You need to be very careful how you handle application updates that change the database structure and/or content when you are allowing the user to write data (that presumably they want to persist between updates).</p>
<p>One way to handle this is to simply have a table in your writable database called &#8220;Version&#8221; which contains one row and one column with the version number of the database schema.</p>
<p>Then in the above code you can add some logic to transfer the data from a pervious schema version to the new writable database file.</p>
<h3>Third Party SQLite Wrappers</h3>
<p>There are <a href="http://code.google.com/p/flycode/source/browse/trunk/fmdb">lots</a> of <a href="http://www.webbotech.com/">SQLite</a> wrappers <a href="http://code.google.com/p/touchcode/">available</a> for iPhone development. I&#8217;ve never used any so I can&#8217;t say if any one is better than another. If the idea of using c-based SQLite calls makes you anxious, you may want to check them out.</p>
<h3>Security</h3>
<p>Someone suggested that I point out that SQLite databases on the iPhone aren&#8217;t really secure. I&#8217;m not a database security expert, but that statement is true of databases on any platform. The database is only as secure as the device itself. If someone gets ahold of your iPhone, they can most likely get the data off of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2008/12/11/iphone-sqlite-database-basics-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Scriptures 1.1.0</title>
		<link>http://leefalin.com/blog/2008/12/08/the-scriptures-110/</link>
		<comments>http://leefalin.com/blog/2008/12/08/the-scriptures-110/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 15:32:48 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=151</guid>
		<description><![CDATA[The Scriptures for the iPhone and iPod Touch version 1.1.0 is now available for download from the App Store. You can read about the changes here. What happened to Landscape mode? Previous version of The Scriptures application had the useful (and expected) feature of being able to rotate the device to read in landscape mode. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.leefalin.com/projects/scriptures/">The Scriptures for the iPhone and iPod Touch</a> version 1.1.0 is now available for <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=287370390&#038;mt=8">download from the App Store</a>. You can read about the changes <a href="http://leefalin.com/projects/scriptures/changelog.php">here</a>.</p>
<h3>What happened to Landscape mode?</h3>
<p>Previous version of The Scriptures application had the useful (and expected) feature of being able to rotate the device to read in landscape mode. Unfortunately due to some technical issues, some of the new features in this version made this feature a bit buggy. Some of these issues were design related, others have to do with a <a href="http://openradar.appspot.com/6399924">known bug</a> regarding how the iPhone SDK handles rotations.</p>
<p>Rather than deliver a substandard user experience, I have pulled this feature until I can fix the issues associated with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2008/12/08/the-scriptures-110/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone SQLite Database Basics</title>
		<link>http://leefalin.com/blog/2008/10/02/iphone-sqlite-database-basics/</link>
		<comments>http://leefalin.com/blog/2008/10/02/iphone-sqlite-database-basics/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 15:09:20 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=145</guid>
		<description><![CDATA[In celebration of the lifting of the NDA on the iPhone SDK, I decided to write a tutorial on using SQLite on the iPhone. This tutorial covers the basics of SQLite database creation, things to consider in the design of the database, and some particular things to be aware of when deploying these types of [...]]]></description>
			<content:encoded><![CDATA[<p>In celebration of the lifting of the NDA on the iPhone SDK, I decided to write a tutorial on using SQLite on the iPhone.</p>
<p>This tutorial covers the basics of SQLite database creation, things to consider in the design of the database, and some particular things to be aware of when deploying these types of applications to the iPhone.</p>
<p>Once you have finished with these basics, take a look at the <a href="http://developer.apple.com/iphone/library/samplecode/SQLiteBooks/index.html">SQLiteBooks</a> sample code from the iPhone dev center for details on how to interface with the database from your code.</p>
<h3>Step 1: Create a SQLite Database File</h3>
<p>There are lots of ways to create a SQLite database file. The easiest way that I have found is to download the <a href="https://addons.mozilla.org/en-US/firefox/addon/5817">SQLite Firefox extension</a>, which provides a GUI to create and manage your SQLite database. The rest of this tutorial will assume you have that extension installed.</p>
<p>In this tutorial we&#8217;ll be creating a recipe application, so we are naming our database &#8220;recipes&#8221;.</p>
<p>To create the database:</p>
<ol>
<li>Click the &#8220;New Database&#8221; toolbar button.</li>
<li>Enter the name of the database file.</li>
<li>Click OK.</li>
</ol>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/10/createdb.jpg" alt="createDB.jpg" border="0" width="626" height="364" /></p>
<p>You will then be prompted for a location to save the database. The ideal place is in the directory of your XCode project.</p>
<h3>Step 2: Create the Database Schema</h3>
<p>Now we are going to setup our database tables. This will be a very simple database with two tables:</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/10/schema.png" alt="schema.png" border="0" width="685" height="261" /></p>
<p>There are entire textbooks about &#8220;proper&#8221; database design and if you are developing a super large-scale ultra robust data warehouse app, you might want to look them over. However rather than make your eyes glaze over with the merits of <a href="http://en.wikipedia.org/wiki/Third_normal_form">third normal form</a>, let me just share a few guidelines that I picked up during several years as a DBA/Database application developer:</p>
<blockquote>
<ol>
<li>Every table should mirror an object, with each non-calculated object property mapping directly to a table field.</li>
<li>In addition to the object properties, every table should have an integer field that is autofilled with a unique identifier (commonly know as the primary key).</li>
<li>Every table that is dependent on a parent table should have a way to refer back to its parent. (This is sometimes called a Foreign Key)</li>
</ol>
</blockquote>
<p>In our application we&#8217;re going to have two model objects. A Recipe object, and an Ingredient object. Each recipe object can have 1 or more ingredient child objects. (The blue arrow in the above diagram signifies this, and is called a 1-to many relationship).</p>
<p>The Recipe object has a name and description property. These are both strings, and these map to database fields of type VarChar (meaning Variable length Character string). In addition, the Recipes table has a Recipe_ID field of type Integer. This field is the primary key of the Recipes table.</p>
<p>The ingredient object in our simple application only has one property, Description. Since this is a string it also maps to a VarChar field. Our Ingredients table also has a primary key (Ingredient_ID) which gives us a way to refer to a specific ingredient.</p>
<p>Finally, the Recipe_ID field in the Ingredients table is our foreign key back to the Recipes table. Using that key you can look at any ingredient and know what Recipe it belongs to. More commonly an application will use that key to get all of the ingredients that belong to a specific recipe.</p>
<p>To create the Recipes table, click the &#8220;New Table&#8221; toolbar button and enter the information as seen below:</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/10/recipetable.jpg" alt="RecipeTable.jpg" border="0" width="690" height="403" /></p>
<p>Notice that we check the Primary Key and Autoinc checkboxes for the Recipe_ID field. The Primary Key checkbox tells SQLite to treat this field as a Unique Index, meaning that it can guarantee that the values in this field won&#8217;t be duplicated and should be kept sorted for faster queries. (Later we&#8217;ll talk a little more about optimizing queries by adding additional table indices.)</p>
<p>The Autoinc checkbox tells SQLite how to handle the automatic creation of primary key values. Without autoinc being checked, when a new row is added SQLite sets the primary key to one greater than the current highest primary key. With the box checked, SQLite sets the primary key to one greater than the highest primary key that the table has every had. (Which it keeps track of in its own table called sqlite_sequence). How you set this box will depend on how you want to handle deleted records.</p>
<p>For the Ingredients table, it is much the same:</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/10/ingredientstable.jpg" alt="IngredientsTable.jpg" border="0" width="690" height="403" /></p>
<p>Notice that we do NOT mark the Recipe_ID field of the Ingredients table as a primary key. It is the primary key of the Recipes table, not of this table. (In this table some people would call the Recipe_ID field the foreign key).</p>
<p>The last thing that we want to do regarding our database schema is to create an index on the Recipe_ID field of the Ingredients table. Since most of our queries that involve this table will involve looking up a specific value in the Recipe_ID field, it will speed things up to have an index on this field. (Note: You really won&#8217;t notice a significant speed increase unless your Ingredients table has a lot of records, but since it is a good design principle, we&#8217;re going to do it anyway.)</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/10/createindex.jpg" alt="createIndex.jpg" border="0" width="690" height="403" /></p>
<p>Finally you need to populate the table with some data. You can do that using the SQLite Manager by selecting the table and then clicking the &#8220;Add new Record&#8221; button, or by selecting the &#8220;Execute SQL&#8221; tab and using several <a href="http://www.sqlite.org/lang_insert.html">Insert statements</a>.</p>
<p>For example to insert this data into my Recipes table:</p>
<table border="1" cellpadding="5">
<tr style="background-color:#CCCCCC;">
<th>Recipe_ID</th>
<th>Name</th>
<th>Description</th>
</tr>
<tr>
<td>1</td>
<td>Omelet</td>
<td>A delicious and eggy breakfast.</td>
</tr>
<tr>
<td>2</td>
<td>Grilled Cheese Sandwich</td>
<td>A delicious and cheese filled lunch.</td>
</tr>
<tr>
<td>3</td>
<td>Pizza</td>
<td>A classic dinner from the old world.</td>
</tr>
</table>
<p>I could use these three insert statements:</p>
<div style="color:#660000">INSERT into Recipes(Name, Description) VALUES(&#8216;Omelet&#8217;, &#8216;A delicious and eggy breakfast.&#8217;);</div>
<div style="color:#660000">INSERT into Recipes(Name, Description) VALUES(&#8216;Grilled Cheese Sandwich&#8217;, &#8216;A delicious and cheese filled lunch.&#8217;);</div>
<div style="color:#660000">INSERT into Recipes(Name, Description) VALUES(&#8216;Pizza&#8217;, &#8216;A classic dinner from the old world.&#8217;);</div>
<p>Notice that I did not insert the values for the Recipe_ID field. As I mentioned above, since it is the primary key the database calculates those values automatically.</p>
<p>Next comes the Ingredients table:</p>
<table border="1" cellpadding="5">
<tr style="background-color:#CCCCCC;">
<th>Ingredient_ID</th>
<th>Recipe_ID</th>
<th>Description</th>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>Eggs</tr>
<tr>
<td>2</td>
<td>1</td>
<td>Water</tr>
<tr>
<td>3</td>
<td>1</td>
<td>Salt</tr>
<tr>
<td>4</td>
<td>2</td>
<td>Bread</tr>
<tr>
<td>5</td>
<td>2</td>
<td>Cheese</tr>
<tr>
<td>6</td>
<td>2</td>
<td>Butter</tr>
<tr>
<td>7</td>
<td>3</td>
<td>Pizza Dough</tr>
<tr>
<td>8</td>
<td>3</td>
<td>Pizza Sauce</tr>
<tr>
<td>9</td>
<td>3</td>
<td>Cheese</tr>
<tr>
<td>10</td>
<td>3</td>
<td>Toppings</tr>
</table>
<p>Which I could use the following statements for:</p>
<div style="color:#660000">INSERT into Ingredients(Recipe_ID, Description) VALUES(1, &#8216;Eggs&#8217;);</div>
<div style="color:#660000">INSERT into Ingredients(Recipe_ID, Description) VALUES(1, &#8216;Water&#8217;);</div>
<div style="color:#660000">INSERT into Ingredients(Recipe_ID, Description) VALUES(1, &#8216;Salt&#8217;);</div>
<div style="color:#660000">INSERT into Ingredients(Recipe_ID, Description) VALUES(2, &#8216;Bread&#8217;);</div>
<div style="color:#660000">&#8230;</div>
<div style="color:#660000">INSERT into Ingredients(Recipe_ID, Description) VALUES(3, &#8216;Toppings&#8217;);</div>
<p>Again notice that I did not specify the values for the table&#8217;s primary key (Ingredient_ID), but I did specify the foreign key values (Recipe_ID).</p>
<h3>Step 3: Add the Database File to Your XCode Project</h3>
<p>To do this, just right click on the Resources folder and select &#8220;Add->Existing Files&#8230;&#8221; and then select the database file that you created.</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/10/addfile.jpg" alt="addFile.jpg" border="0" width="637" height="361" /></p>
<p>XCode should automatically add the file that you select to the &#8220;Copy Bundle Resources&#8221; build phase of your project target. (Meaning that when the program is compiled, your database file is automatically stored in the application bundle&#8217;s resource folder so that you can access it from your application.)</p>
<p><strong>Update: </strong><a href="http://toxicsoftware.com/">Jonathan Wight</a> suggested that instead of embedding the SQLite db file directly into the XCode project, it is better to embed the SQL source file into the project and then setup a compile rule in XCode to generate the db file and embed it into the bundle at compile time. As he points out this has a particular advantage related to source code control. He provides an example of how to do this <a href="http://public.toxicsoftware.com/CompileSQL.png">here</a>.</p>
<h3>Step 4: Link to the SQLite Library</h3>
<p>Finally you are ready to link to the library that contains all of the SQLite functions. To link to that library, from your XCode project right click the frameworks folder and select &#8220;Add->Existing Frameworks&#8230;&#8221;.</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/10/addframework.jpg" alt="addFramework.jpg" border="0" width="566" height="279"/></p>
<p>Next, navigate to the your iPhoneSDK folder and select the usr/lib/libsqlite3.0.dylib file. (Don&#8217;t be confused by the other libsqlite*.lib files in that folder, they are all just aliases to this one.)</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/10/xcode-1.jpg" alt="Xcode.jpg" border="0" width="594" height="357"/></p>
<p>You are now ready to start writing some SQLite code. (Again see the <a href="http://developer.apple.com/iphone/library/samplecode/SQLiteBooks/index.html">SQLiteBooks</a> sample code for some tips on doing that.)</p>
<p><strong>Update: </strong><a href="http://toxicsoftware.com/">Jonathan Wight</a> also suggested that it is better to use the other linker flags setting in the the Build tab of the Project settings to link to the SQLite library instead of using the framework method. You can do this by adding the -lsqlite3 flag to that field as shown here:</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/10/project-sqlitebooks-info.jpg" alt="Project “SQLiteBooks” Info.jpg" border="0" width="656" height="196" /></p>
<p>This method has the advantage of linking to the correct library no matter what platform you are targeting.</p>
<h3>SQLite on the iPhone Nuances</h3>
<ol>
<li>SQLite on the actual iPhone is much slower for some things than on the simulator. In particular the same queries that run in the blink of an eye on the simulator take several seconds to run on the actual device.</li>
<li>If you need to write to your database, make sure you make a copy of it in a location that you can write to. See the <a href="http://developer.apple.com/iphone/library/samplecode/SQLiteBooks/index.html">SQLiteBooks</a> sample code for an example of how to do this.</li>
<li>Be aware that SQLite extensions such as Full Text Search don&#8217;t appear to be compiled into the iPhone SQLite libraries.</li>
<li>Plan for the future! If you plan on adding a feature that relies on a certain table or field in the database make that part of your database design now. This will save you the trouble of having to write all the necessary SQL commands for versioning your database later when you release an application update.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2008/10/02/iphone-sqlite-database-basics/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Scriptures Update &#8211; Call for Localizers</title>
		<link>http://leefalin.com/blog/2008/09/26/scriptures-update-call-for-localizers/</link>
		<comments>http://leefalin.com/blog/2008/09/26/scriptures-update-call-for-localizers/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 04:55:41 +0000</pubDate>
		<dc:creator>Lee Falin</dc:creator>
				<category><![CDATA[iOS Programming]]></category>

		<guid isPermaLink="false">http://leefalin.com/blog/?p=136</guid>
		<description><![CDATA[The Scriptures 1.0.4 for iPhone / iPod Touch is now available for download. This release contains a couple of bug fixes and new features. What&#8217;s New One feature that has been consistently requested is the ability to navigate between chapters. There are now buttons on the title bar that allow you to do just that. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=287370390&#038;mt=8">The Scriptures 1.0.4</a> for iPhone / iPod Touch is now available for download. This release contains a couple of bug fixes and new features.</p>
<h3>What&#8217;s New</h3>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/09/newlargeicon.jpg" alt="newLargeIcon.jpg" border="0" width="64" height="64" align="left" style="padding-right:12px;" />One feature that has been consistently requested is the ability to navigate between chapters. There are now buttons on the title bar that allow you to do just that. These buttons also allow you to quickly navigate between search results.</p>
<p>I&#8217;ve also added the ability to change font styles. Though I personally think The Scriptures look better in a serif font, a few people have asked for the ability to change to a sans-serif view. You can now make that change in the application settings.</p>
<p>Finally, I also added the really nice icon that <a href="http://gaigeredd.com/">Gaige Redd</a> has contributed. I really wanted to keep the <a href="http://eom.byu.edu/index.php/Moroni%2C_Angel">Angel Moroni</a> theme and Gaige did a great job with it.</p>
<p>There were also a few bug fixes, which you can read about in detail in the <a href="http://leefalin.com/projects/scriptures/changelog.php">changelog</a>.</p>
<h3>What&#8217;s Next</h3>
<p>There are three things that I&#8217;m currently working on and hope to be done with soon:</p>
<ol>
<li><strong>More Content</strong> &#8211; Everyone wants more content. I&#8217;m not sure what will be added when, but I can tell you that the first things I want to include are chapter headings, footnotes, and study helps.</li>
<li><strong>Bookmarks and Annotations</strong> &#8211; Coming very very soon. The tricky part with this isn&#8217;t the coding. It is trivial to mark spots in the scriptures, or to create a list of saved locations to navigate to. The tricky part (as with any new feature) is the UI Design. On a device like the iPhone especially it is critical to get the UI right. I&#8217;ve been working at this and I think that you will like the UI design that I&#8217;ve settled on.</li>
<li><strong>Localizations (aka Translations)</strong> &#8211; I have gotten so many requests for translations as well as offers for help, and this is a priority item that I want to get done soon. (More on this below) </li>
</ol>
<h3>Calling all Localizers</h3>
<p>In the software development world implementing an application in a new language is commonly called <em>localization</em> rather than translation for a couple of reasons.</p>
<p>First of all you aren&#8217;t just translating the content, you are also converting the UI to work as expected in the <em>locale</em> where the new language is spoken. That means things like dates and currency should be appropriately converted.</p>
<p>Also, localization (especially of the UI) doesn&#8217;t just mean translating the commands word for word with a dictionary. Just as in English, every language has certain idioms and conventions that are used in technology that go beyond a simple translation. For example look at this screenshot of iTunes in its Brazilian Portugûese localization:</p>
<p><img src="http://leefalin.com/blog/wp-content/uploads/2008/09/itunes.jpg" alt="iTunes.jpg" border="0" width="527" height="269" style="padding-right:12px;" /></p>
<p>Notice how the &#8220;View&#8221; menu is localized as &#8220;Visualizar&#8221; which is literally &#8220;To Visualize&#8221; rather than &#8220;Vista&#8221; which is the noun for view. Also notice how the &#8220;Store&#8221; heading is localized as &#8220;Loja&#8221; which is a direct translation for store, but that &#8220;iTunes Store&#8221; is left alone. Also, &#8220;Ringtones&#8221; is localized as &#8220;toques&#8221; which literally means the plural noun &#8220;touches&#8221;.</p>
<p>Why am I telling you all of this? Because I need your help. While I am fluent in English and Brazilian Portûguese because of <a href="http://leefalin.com/blog/about/">the time I spent in Brazil</a>, there are many other languages that I would like to do localizations for. (And even for Portûguese I don&#8217;t know all of the necessary technical conventions needed for the UI localization).</p>
<h4>Desired Qualifications</h4>
<p>If you would like to help, here are the qualifications:</p>
<ol>
<li>You must be a native speaker or have near native fluency in the language you want to help localize.</li>
<li>You must have experience using software in the language you want to help with. (So you&#8217;ll know those conventions I mentioned above).</li>
<li>You must be willing to install buggy beta software on your iPhone or iPod Touch.</li>
<li>You must know how to find your <a href="http://www.tuaw.com/2008/08/08/iphone-101-find-udid-with-a-single-click/">iPhone&#8217;s Unique Device Identifier</a>. (I need this in order to make the beta software run on your device)</li>
<li>Previous experience as a beta tester/localizer is preferred, but not necessary.</li>
<li>You should know <a href="http://connect.microsoft.com/content/content.aspx?ContentID=2612&#038;SiteID=235">how to write a good bug report</a>.</li>
<li>You must be willing to do this for absolutely no compensation.</li>
</ol>
<h4>The Localization Process</h4>
<p>The localization process will basically work like this:</p>
<ul>
<li><span style="font-size: 14px; color:#006600; font-variant:small-caps">You</span> will email me with your name, the language(s) you would like to assist with and the UDID of your iPhone or iPod Touch.</li>
<li><span style="font-size: 14px; color:#660000; font-variant:small-caps">I</span> will email you a list of terms from the user interface that need to be localized.</li>
<li><span style="font-size: 14px; color:#006600; font-variant:small-caps">You</span> will email me back a list of localizations for each of those terms in the form: &#8220;English Term: Localized Term&#8221;</li>
<li><span style="font-size: 14px; color:#660000; font-variant:small-caps">I</span> will make the necessary updates in the application to incorporate the localization.</li>
<li><span style="font-size: 14px; color:#660000; font-variant:small-caps">I</span> will send you a beta version of the software containing the localization along with instructions on how to install it.</li>
<li><span style="font-size: 14px; color:#006600; font-variant:small-caps">You</span> will install the beta software and test it, paying special attention to the localizations.</li>
<li><span style="font-size: 14px; color:#006600; font-variant:small-caps">You</span> will send me <a href="http://connect.microsoft.com/content/content.aspx?ContentID=2612&#038;SiteID=235">reports for any bugs that you find.</a></li>
<li><span style="font-size: 14px; color:#660000; font-variant:small-caps">I</span> will fix the bugs that are reported, create a new version of the beta software, and email it to you.</li>
<li><span style="font-size: 14px; color:#006600; font-variant:small-caps">You</span> will install the new beta software and test it, paying special attention to the localizations.</li>
</ul>
<p>Once everyone is satisfied that there are no problems with the localization, the update will be submitted to the App Store for distribution.</p>
<p>If after reading this you are interested in helping out, you may send me an email with your name, device UDID, and the language(s) you would like to assist with. I can&#8217;t guarantee that every language will be done, nor the order that I will go in, but I will do as many as I can that the Scriptures are available for in digital form.</p>
<p>You may email me at: <span class="emailAddress">lee <span class="emailMeta">&lt;dot&gt;</span> falin <span class="emailMeta">&lt;at&gt;</span>gmail  <span class="emailMeta">&lt;dot&gt;</span> com</span></p>
]]></content:encoded>
			<wfw:commentRss>http://leefalin.com/blog/2008/09/26/scriptures-update-call-for-localizers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

