Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Coding the testbed

From: iOS SDK and SQLite: Building Data-Driven Apps

Video: Coding the testbed

At this point we have built the text view in the interface builder, and we just need to plug in the code to make the testbed work. The results of what I did in the previous movie are in this Testbed-02-done folder, and that's actually our project folder. And so I'm going to take that folder, and I'm going to copy it, and I'm going to paste it into this Chapter 1 folder, and I'm just going to rename it to Testbed-O3, because this is Movie 3 in this chapter. And I'm going to open the project by double clicking on Testbed.xcodeproject.

Coding the testbed

At this point we have built the text view in the interface builder, and we just need to plug in the code to make the testbed work. The results of what I did in the previous movie are in this Testbed-02-done folder, and that's actually our project folder. And so I'm going to take that folder, and I'm going to copy it, and I'm going to paste it into this Chapter 1 folder, and I'm just going to rename it to Testbed-O3, because this is Movie 3 in this chapter. And I'm going to open the project by double clicking on Testbed.xcodeproject.

And that will invoke Xcode, and it will open the project. And I can navigate over here to Testbed View Controller.m, and I'm going to close the Inspector pane. I'm actually going to close the Assistant Editor as well and just come over here to the Plain Editor, and that gives the maximum amount of room. You're on this limited real estate. You can leave all that stuff open if you like on your screen, because you probably have a lot more room on your screen than I do.

So, this is our whole view controller class here. And so, the first thing I'm going to do is I'm going to bring in some library code from our exercise files. So under Libraries here, I'm going to grab this BWUtilities folder, and I'm just going to drag it over here into our project. You see I'm dragging it where it says Testbed, not in any of these other places just right there in that Testbed folder, and I'm going to let go of it. And you'll notice here in Xcode, I get this little dialog box. I want to make sure I select copy items, and create groups for any added folders and Add to targets has to have Testbed checked.

So, what that does is that it copies the libraries from BWUtilities folder into our project. If I don't have this checked, then it won't copy, it will just use it in place, and that's not really what we want. We want to copy it into the project, and I Create groups for any added folders, and you'll see what that will do here in a moment. It will create a group that looks like a folder in this display here. And Add to targets means it is going to get compiled into this Testbed target, and we need that in order to be able to use the code.

So, I'm going to say Finish, and there's our BWUtilities folder and just has this BWUtilities.m and BWUutilities.h. And all this is a few functions that are useful for our Testbed. Here's the message function and our alert message so we can display alerts, flattenHTML trim string. These are things that we use throughout the project. We're also going to use them in the final RSS reader project, or at least some of them. And then in the h file, we have our interface.

Now, it's not actually a class in the strictest sense. It's not using object oriented techniques, these are all individual functions, because they are actually more useful that way, and the way that we are going to be using them. But the h file exposes this interface to rest of the codes so that we can actually use the functions in the .m file. So, I'm going to close that group. So, that's the group that we created. It looks like a folder in this interface, but it's actually called a group. Now I'm going to come over here in the TestbedViewController.h, and I'm going to come down here, and I am going to say import and in the double quotes I'm going to say, "BWUtilities.h", and you see the code completion is right there already.

And I'm also going to come down here, and I'm going to create a static string. And I'm going to make it constant. I'm going to call it kTestbed. So, using a k at the beginning of a variable name means it's a constant. That's a convention that's often used in Objective-C. And kTestbedVersion equals and 1.0, and a semi-colon. I'm going press command S to save this file and then I'm going to switch to the .m file.

So now, we've included our utilities when we created a string for our version. And under viewDidLoad here, I'm going to just start adding a little bit of code. First time I'm going to declare an external variable, extern, and it's a UITextView, and it's a messageTextView. And you'll notice that that variable is actually declared in our BWUtilities.h, and there it is. So, what I'm going to do is I'm going to populate that variable so that the utilities knows where our TextView is so that it can display stuff in our TextView.

So, I'm going to say, messageTextView = textView. So, that tells the BWUtilities where our textView is so that it can actually post messages to it. And I'm going to set the font in our textView, so it sets it to a system font of size 12. And I'm going to run a function called RunTest, which we have not declared yet. So, I'm going to say self runTest.

And we're going to get a littler error here, because it's not declared yet, and I'm going to come up here above it, and I'm going to declare it. I'm going to say (void) runTest, and now, we don't have an error down here anymore, because we have a function called runTest. In our runTest, I'm going to display a message, and it is going to say Testbed version, and I'm going to use our kTestbedVersion variable there. So, the message function actually is variadic function, it works just like printf does.

You'll notice here in the code it actually calls format. So, it's a variadic function, it has va_list and va_start just like a normal variadic function in C and feel free to check out my C and C++ Essential Training for tutorial on how variadic functions work. And here, it uses NSString initWithFormat, which is very much like format using C, and it passes at the argument so that it works like a normal variadic function. So, that allows me to do things like this %@ to display Objective-C object.

So now, we're going to display a series of strings like this. And this is using the new Objective-C literal object syntax. So, this is called a boxed array, and it's a much easier way to declare an array than the old way. So, I can just declare a bunch of strings in here in this array like that, and then inside in each of the strings I can put some text.

So now we have our little runTest function. It will display the TestbedVersion, and that constant is declared in our .h file, and it steps through this boxed array and displays each of these strings individually. So, when I save this, and I'm going to make sure I've selected the iPhone 6.0 simulator and press Run. It will go ahead and compile it, Build Succeeded, and it will bring up the simulator, and there it is it's running.

And you'll notice that these messages are now displaying in our text view. So now, we have a working iOS testbed. I find this a very valuable tool. Whenever I have a specific task to accomplish, I'll start with the testbed like this one, and I'll do some prototyping to try out different approaches and decide on a strategy. This saves me a lot of time and headache that I would otherwise spend trying to debug a new idea while it's intermingled with other working code. We'll see an example of how to use this in the next movie.

Show transcript

This video is part of

Image for iOS SDK and SQLite: Building Data-Driven Apps
iOS SDK and SQLite: Building Data-Driven Apps

41 video lessons · 6435 viewers

Bill Weinman
Author

 
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 learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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.

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?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

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 preferencesfrom 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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.