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

Testing the BWDB interface in the sandbox


From:

iOS SDK and SQLite: Building Data-Driven Apps (2013)

with Bill Weinman

Video: Testing the BWDB interface in the sandbox

At this point we have started to incorporate BWDB in the Testbed code for testing. We've set up the SQLite 3 Framework in Xcode, and we've imported the BWDB Library into our Testbed app. Now, it's time to test the library in the testbed. So, you're going to take the results from your last exercise or if you prefer, you can use Testbed-02-done, which is my version. And I'm going to make a working copy of this. And I'm just going to call it Testbed-03-working, and so this way we can pick up where we left off at the end of the last movie.
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

please wait ...
Watch the Online Video Course iOS SDK and SQLite: Building Data-Driven Apps (2013)
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

Testing the BWDB interface in the sandbox

At this point we have started to incorporate BWDB in the Testbed code for testing. We've set up the SQLite 3 Framework in Xcode, and we've imported the BWDB Library into our Testbed app. Now, it's time to test the library in the testbed. So, you're going to take the results from your last exercise or if you prefer, you can use Testbed-02-done, which is my version. And I'm going to make a working copy of this. And I'm just going to call it Testbed-03-working, and so this way we can pick up where we left off at the end of the last movie.

And I'm going to double-click on the Testbed. xcodeproject inside of that folder to open the project in Xcode. So, we have our BWDB Library, there is the m file, and there is the h file. I'm just going to close that up for now, we go to our BWUtilities. And I'm going to come over here to the TestbedViewController.m file, and up here at the top I'm going to import the BWDB header. And I'm going to come back out here into our finder, and I'm going to take this BWDB testbed code and open that up in my text editor. And we've got a couple of methods here.

I'm just going to copy these and paste them into my m file. So, Command+C to copy, coming back here into Xcode, and down here in the implementation I'm going to paste those in, and there they are. And you see that our method here is called testDatabase. And so, I'm just going to come down here in viewDidLoad and instead of runTest, I'm just going to type in testDatabase like that.

And so runTest here is actually often we can leave it there, or you can delete it, it's up to you. So, let's just go ahead here and run this and then we'll come back, and we'll look at the code. Make sure you select the iPhone Simulator and press the Run button, Build Succeeded, that's always a good sign. And so there is the Simulator, we see we have our BWDB version, SQLite version, create table, and all of these database operations happening successfully.

So, let's take to look at the code. So, there's a table name and a file name. And there is an actual BWDB object being declared. And here we have our alloc init pattern, and we're initializing with the file name and the table name. And we call getVersion to display the version, and there is our version there. And SQLite version is value from query select sqlite_version, so there is the sql query to get the SQLite version, and that's getting displayed here.

So, that actually tells us that a lot of stuff is working here. Our interface to the SQLite Framework is working and the interface to BWDB is working. So, we're actually able to send an SQL query and get a value from that, and that's a really good sign. So now, we come out here, and we create a table. You notice I have this message call to create--to display the create table string. And doQuery is the version of the query code, and if we come in here to the BWDB header and SQL query's doQuery simply returns a number of rows that were affected, if any.

So, it's typically called without testing the return value. And we come back down here, and we can see doQuery here has been called without testing the return value. Drop table if exists and then CREATE TABLE. We're creating a table with an id column, INTEGER PRIMARY KEY that's SQLite for an auto incremented integer key. SQLite allows you to create columns without a type because it's really a very loosely typed thing anyway.

And stamp is TEXT DEFAULT CURRENT_TIMESTAMP and so it will always put a timestamp on every single row. And so, now we're going to go ahead and insert a row, and we insert into BW table, so we're using doQuery for this insert, and we return the lastInsertId, and we see that we get one for that. And then using CRUD to insert with insertRow, and these are literal NSDictionary types.

So, we have key value, key value, key value, that's a new feature in Objective-C, and it's much more convenient than the old way. So, I tend to use these literal values a lot. So, you see I'm using some different types here, I've got the literal floating point, I've got literal integers and here is a literal string. So, NSNumber doubles, integers and Mixed. And you see, when we look at these values, we get the return values based on the way that SQLite handles these sorts of things.

And here I'm reading it back, and that's where it's displayed here using the NSFastEnumeration. And so, I simply pass the query into the db object and for a row in, the value that's returned by that is the actual db object. If we look at the getQuery code over here, we notice that it returns itself. So, that's actually returning the BWDB object. And because of NSFastEnumeration, I'm able to just say for row in that object, and then call display row with that row.

And display row of course is up here, and it's just this simple message with the row. And again, we're using this new subscripting feature that's new in Objective-C. So, we use db countRows here, and there we have count rows 4, and then we delete a row and then we get count rows 3. So here, we delete row three with deleteRow, and we call countRows again we get a different value. And then we look, and we have just row 1, row 2 and row 4, and that again is using the NS enumeration for displaying the rows in the table.

And then we're able to display an individual row using getRow. So, this should make it clear that the value of this wrapper is it makes it easy to work with SQLite in an Objective-C environment. We are using Objective-C paradigms for all of this, rather than having to write C code in the middle of our Objective-C. It makes this all seamlessly integrate with our Objective-C code for iOS. It's also easy as we'll see in another lesson in this chapter to subclass BWDB and create a specific interface for a specific application.

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


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 (2013).

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


OK

Upgrade to View Courses Offline

login

With our new Desktop App, Annual Premium Members can download courses for Internet-free viewing.

Upgrade Now

After upgrading, download Desktop App Here.

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:

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.

Start your FREE 10-day trial

Begin learning software, business, and creative skills—anytime,
anywhere—with video instruction from recognized industry experts.
lynda.com provides
Unlimited access to over 4,000 courses—more than 100,000 video tutorials
Expert-led instruction
On-the-go learning. Watch from your computer, tablet, or mobile device. Switch back and forth as you choose.
Start Your FREE Trial Now
 

A trusted source for knowledge.

 

We provide training to more than 4 million people, and our members tell us that lynda.com helps them stay ahead of software updates, pick up brand-new skills, switch careers, land promotions, and explore new hobbies. What can we help you do?

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.