iOS SDK and SQLite: Building Data-Driven Apps
Illustration by Don Barnett

Supporting the application with a specific interface


From:

iOS SDK and SQLite: Building Data-Driven Apps

with Bill Weinman

Video: Supporting the application with a specific interface

At this point, we have a working SQLite 3 database wrapper class called BWDB and a working SQLite 3 database called bwrss.db. Now we want to take these components and make an Objective-C class for using these components in iOS. So we will start by making a working copy of our project so far. So you can make a working copy of your results from movie three or like I am going to do here, I am just going to make a working copy from Testbed-03-done, and I am going to rename this to Testbed-05-working.
Expand all | Collapse all
  1. 8m 29s
    1. Welcome
      57s
    2. Exercise files
      2m 17s
    3. Course overview
      3m 4s
    4. Application overview
      2m 11s
  2. 14m 49s
    1. Prototyping in a testbed
      1m 27s
    2. Building the view controller
      3m 45s
    3. Coding the testbed
      7m 56s
    4. Using the testbed
      1m 41s
  3. 37m 49s
    1. Understanding SQLite in iOS
      1m 41s
    2. Creating an Objective-C interface for SQLite
      9m 57s
    3. Testing the BWDB interface in the sandbox
      7m 1s
    4. Designing a database schema
      8m 7s
    5. Supporting the application with a specific interface
      7m 7s
    6. Using C pointers with automatic reference counting (ARC)
      3m 56s
  4. 21m 18s
    1. Understanding the table view
      1m 33s
    2. Creating the view controller
      6m 39s
    3. Reading from the database
      13m 6s
  5. 33m 50s
    1. Understanding the parsing process
      1m 57s
    2. Creating the item view controller
      12m 25s
    3. Reading data from the internet
      5m 30s
    4. Parsing the feed with NSXMLParser
      8m 2s
    5. Updating the item view with the feed items
      5m 56s
  6. 40m 14s
    1. Understanding the modal view
      1m 47s
    2. Constructing the view controller
      15m 5s
    3. Finding a feed link in a web page
      8m 55s
    4. Parsing the feed with NSXMLParser
      5m 4s
    5. Delegating back to the parent view
      6m 11s
    6. Deleting feeds
      3m 12s
  7. 21m 5s
    1. Creating the web view class
      12m 33s
    2. Coding the web view
      5m 25s
    3. Viewing pages in Safari
      3m 7s
  8. 14m 3s
    1. Understanding the iOS preferences system
      1m 23s
    2. Creating the preferences plist in Xcode
      7m 20s
    3. Reading preferences in your application
      5m 20s
  9. 6m 15s
    1. Adding pull-to-refresh functionality
      2m 34s
    2. Implementing the pull-to-refresh gesture for iOS 6
      3m 41s
  10. 27m 1s
    1. Understanding split view
      1m 4s
    2. Coding the table views
      11m 24s
    3. Implementing the iPad detail view
      6m 35s
    4. Implementing the iPad modal view
      7m 58s
  11. 35s
    1. Goodbye
      35s

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course iOS SDK and SQLite: Building Data-Driven Apps
3h 45m Intermediate Jan 16, 2013

Viewers: in countries Watching now:

The iOS software development kit (SDK) includes the popular SQLite library, a lightweight yet powerful relational database engine that is easily embedded into an application. In this course, Bill Weinman teaches you how to build an RSS reader for iOS devices, integrating XML data and a streamlined interface. He explains how to use the SQLite database, display information in a table view, code view controllers, and create a preferences pane for your app. The resulting application is optimized for all iPhone and iPad displays.

Topics include:
  • Prototyping the app
  • Coding and working with a testbed
  • Creating an Objective-C interface for SQLite
  • Designing a database schema
  • Creating the view controllers
  • Reading and writing to the database
  • Parsing the RSS feed with NSXMLParser
  • Updating the item view with feed items
  • Implementing the pull to refresh gesture for iOS 6
  • Creating a universal application with multiple views
Subject:
Developer
Software:
iOS
Author:
Bill Weinman

Supporting the application with a specific interface

At this point, we have a working SQLite 3 database wrapper class called BWDB and a working SQLite 3 database called bwrss.db. Now we want to take these components and make an Objective-C class for using these components in iOS. So we will start by making a working copy of our project so far. So you can make a working copy of your results from movie three or like I am going to do here, I am just going to make a working copy from Testbed-03-done, and I am going to rename this to Testbed-05-working.

I am going to open up the project here in Xcode by double-clicking on the Xcode project file. Here we've got our BWDB Library, and you notice our testdatabase method here in our ViewController. I'm going to come right back over here to the Finder, and I am going to--first of all, I'm going to read-in our database. This is the database we created in the last movie, bwrss.db. I'm just going to drag this over here into our target, and you notice that I get this dialog box.

I want to make sure Copy is checked, and I also want to make sure Add to Target is checked for our Testbed target. I'll click Finish, and there's the file there, right next to the dynamic library. And now I'm going to come back out here in the Finder, I am going to Libraries, and I am going to do the same thing. I am going to drag this RSSDB folder, and we'll take a look at this one as we import it. This is going to go in our Testbed group here inside of the target. I'll let go of that and make sure that Copy and Create Groups and Testbed are all selected, and there is our RSSDB code.

If we look up here at the Header File, we see that what we are doing is we're extending the BWDB class, with a new class called RSSDB. This new class has got a bunch of methods in it. This is all specific for dealing with feeds and items. If we come over here into the m file, the implementation file, you see we've got a new constructor that calls the super constructor. That's the constructor of the parent class, the inherited class, and it initializes a list of id's, and it sets some defaults.

So it is basically extending it with file name constructor from the parent class. getVersion is just over written. This getMaxItemsPerFeed, that's reading a preference pane value, we'll get to that later on in the course. This addNewIndex, there was a previous version of this App, which used a database file that did not have an index, and so it just creates the index if it doesn't exist. You'll notice that it is just using SQL for that, and it's calling doQuery on the parent class.

RSSDB because it inherits BWDB, everything in BWDB is available. As a result of that, all of these methods that have to do specifically with feeds and with items, these are all very, very simple and straightforward some of them have some SQL in them but they are just calling doQuery from the parent class. So it makes it really easy because we already have this wrapper, it makes it really easy to write these functions that are very specific for this application and to simply put them in a class extension.

Some of the most complicated stuff like this deleteOldItems is all accomplished in SQL. So you can see that it makes this job a lot easier that we can just extend a class that's already written, that's already wrapping the SQLite C interface in a nice Objective-C interface. Now, we can come out here to our TestbedViewController. Instead of BWDB here, we are going to import RSSDB.h.

Now, we are going to come down here in our dispRow and our Test database. We are just going to replace those. So I'm going to select all of that, and I'm going to come back out here to the Finder, and in Chapter 02, RSSDB-testbed-code.txt, I'm just going to select all of that and copy it and come back over here into Xcode and paste that in. You can see that's very simple, so I am pressing Command+S to save. You see all this does is it initializes this RSSDB object.

It passes it the file name bwrss.db, that's the database that we created in the last lesson, and we've already copied it into our project. It just displays the RSSDB version, and it reads these feed id's and displays them. Now we are going to make sure that the iPhone Simulator is selected and go ahead and run this in the Simulator. There we have our results. It is possible that you may get just the version number and not the actual database.

There may be some errors down here on the screen. If that's the case, what you need to do is you need to actually delete the App from the Simulator and run it again. The reason for this is if this App has been loaded before, and it did not have the database in it, and then you load the database in Xcode and run it in the Simulator, it may not actually replace the whole bundle in the Simulator. So you have to delete the bundle and load it again. It sounds complicated, but if you just follow these steps, it should work.

The first thing I am going to do is I am going to select Xcode, press Command+Dot, and that will bring up this message Finished running Testbed on the Simulator. Let's switch back to the Simulator, I am going to click on Testbed here and hold it down, you notice that it does this little wobbly thing just like on your iPhone when you go to delete something. I am going to press the Delete, and I am going to actually delete that whole bundle. Because my Simulator is the small version because I have the small screen, there is no button, I happen to know that Command+Shift+H presses the Home button.

You see that the whole second page is gone now, because there is no App that goes there. You may have other Apps there, and that's fine. You just want to make sure deleting this one. Now I come back over here to Xcode. I have deleted the bundle off of the Simulator, and when I run it again, it is going to load up the correct bundle. You see that now we have the database. If you get that condition where it just shows the RSSDB version number, and it doesn't show any of the data that is probably because you've got an old version of the bundle on your Simulator that didn't have the database in it. You just delete that bundle, run it again from Xcode, and it should load up the correct bundle with the database in it.

Here, we are just displaying these rows from the database, and we're showing that our App Specific Interface is working. As we go through the rest of the application the rest of this course, we will be using and discussing more of the methods from this library. An App Specific Database Interface is a simple technique, and it is a powerful tool. As your apps get larger, this technique becomes more and more valuable. I find that it is almost always worth the effort.

Find answers to the most frequently asked questions about iOS SDK and SQLite: Building Data-Driven Apps .


Expand all | Collapse all
please wait ...
Q: Why is the RSSDB library in the exercise files different than the one in the videos?

A: The RSSDB library had to be updated to work around a bug in the iOS 7 SDK.

There is a bug in the iOS 7 SDK that prevents the BWDB fast enumeration implementation from working on a device. The symptom is code that runs fine on the emulator, but not on a device. iOS devices use an ARM processor, while the emulator runs on your Mac's Intel processor. This points to the LLVM ARM code generator as the source of the bug. Because the bug appears to be in the LLVM compiler, it may be some time before it is fixed.

As a workaround we have changed the getFeedIDs and getItemIDs methods in the RSSDB library so they don't use Objective C fast enumeration. 

Please note that this same bug also affects some of the BWDB testbed code in Chapter 2. The result is that it will run on the emulator but not on a device.

Q: After upgrading to Xcode 5.1 I get an error that says:

"Used type va_list (aka_builtin_va_list) where arithmetic or pointer type is required"

A: Please download the exercise files again to get the latest version of the BWDB library.
Q: I'm using Xcode 6. Why am I getting error messages with the exercise files?
A: A lot has changed in iOS since this course was released. The author is in the process of rewriting the code and updating the course for iOS 8. In the meantime he has prepared a version of the app that works in iOS 8 and Xcode 6. Download it here:
 
http://ios.bw.org/
 
 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed iOS SDK and SQLite: Building Data-Driven Apps.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.