Last week at RailsConf I taught a 3-hour tutorial on Mobile App Development with iPhone/iPad and Rails. If you’re looking to create a native iPhone app that talks to a Rails app via RESTful resources, this may be of interest to you. The workbook and source code are available on GitHub.

The workbook is designed so you can work through it at your own pace. It’s a stepwise learning approach that we follow in all of our courses. Each section starts with an objective and includes steps to guide you to the solution. Later sections have more open-ended exercises to encourage comprehension. Incremental versions of the iPhone app, and the final Rails app, are also included for reference. Even if you didn’t attend the tutorial you should be able to follow along in the workbook and learn something new.

The overall goal is to build a full-featured iPhone app that talks to a Rails app using RESTful resources. Now, you can pull this off using any number of third-party libraries. But I learn best by distilling problems like this down into incremental steps. So we start with a table-based iPhone app that uses an array populated with local data. Then we replace the contents of the array with remote data using the networking APIs built into Cocoa Touch and a simple JSON library. Building on that foundation, we create a class that can handle all the REST verbs. At that point we have an iPhone app that can create, read, update, and delete a resource living in the Rails app. And, more importantly, we understand how it all works. From there we begin surveying several libraries—HTTPRiot, ASIHTTPRequest, and ObjectiveResource— to replace our custom class and offer more advanced features. Along the way we delve into topics such as asynchronous communication, authentication, and nested resources. Because we approach the problem in a stepwise fashion, each new concept builds on what you already know. That kind of informed programming means you can use, extend, and debug the library you choose with more confidence.

This was all fairly ambitious for a 3-hour tutorial which is why it assumes you have a working knowledge of Rails, Objective-C, and the iPhone SDK. Preparation instructions were sent out to attendees so we could hit the ground running. If you’re new to Rails or iPhone programming, I hope you’ll consider attending our 3-day Ruby on Rails course or our 4-day iPhone Programming course.

With Rails 3 and iPhone 4 due to be officially released this summer, it’s a great time to be coding in both worlds. Have fun!