Big Nerd Ranch's iPhone Programming

This is a brief review of the second cocoa book I’ve read the past month. This particular book was focused on Cocoa Touch for the iPhone OS as compared to my first review of Cocoa and Objective-C: Up and Running which primarily covered cocoa apps for Mac OS X.

iPhone Programming by Joe Conway and Aaron Hillegass

Very first thing I noticed were the number of chapters that are included in this book. Overall, there are 28 chapters that span 381 pages. I thought this was great since most of the chapters would be small enough for me to complete in several hours (including exercises). I love that each chapter focused on key concepts of Objective-C and Cocoa frameworks. I approached this book with the goal of reading one chapter a day as suggested by the authors. The authors of the book also indicated that the material is based on their iPhone Development Bootcamp course. So I treated each chapter as an individual class. Again, I decided to start from the beginning with chapter 1 and work my way through the entire book.

The first few chapters cover the creation of a simple iPhone application and some core concepts of the Objective-C language. The chapter on Objective-C basics deals with the fundamentals of creating a class, initializing an object, setting up accessors and class methods. Great stuff and no doubt essential topics that are required when creating an iPhone app. One of my favorite chapters is the one devoted to Memory Management (chapter 3). This chapter does a fantastic job of describing manual reference counting and utilizing retain counts. The way they describe the dangers of releasing an object too early if a new owner of that object never retained it was straight forward. In fact, there is a simple example using this concept of passing a grocery list to your friend. This example shows you two ways of shooting yourself in the foot if you mis-handle your retain counts. You can either create a memory leak or deallocate an object prematurely. The authors do a good job of laying out the details of how easily it would be to make these errors. These are two common mistakes made by beginning iPhone Programmers. Then there is a nice transition from their description of how easy it is to create memory leaks to a nice discussion on how to avoid them using autorelease. This chapter alone is worth the price of the book. Memory management made absolute sense to me upon finishing this chapter.

Upon finishing the basics, the book dives right into iPhone development with chapter 4 (Delegation and Core Location). I love that the authors decided to use an actual framework (CoreLocation.framework) to teach you the basics of delegation. Choosing the CoreLocation.framework to demonstrate the use of protocols and showing how the stock AppDelegate conforms to the CLLocationManagerDelegate was a great idea. This example shows the reader how they can incorporate great iPhone SDK features into their own applications. This sort of content keeps the reader engaged and eager to get to the next chapter. Using an actual framework instead of some contrived code sample to demonstrate this important topic gives the reader some real world context. If you decide to go a step further and display your location on a map, you apply the same exact concepts when adding the MapKit framework. Select an object to conform to the protocol, look up the protocol in the reference guide, figure out which delegate methods to implement, create an instance of the delegate, inform the delegate of the object that implements the delegate methods. The authors describe these steps in an easy and seamless fashion. It’s very easy to follow along. This is such an important concept for beginners to understand and the authors did a wonderful job of explaining it. An iPhone app is one large delegate. You need to grasp the concepts of protocols and delegates if you plan to make any meaningful progress when developing your iPhone app.

UIView, ViewControllers and UITableViewControllers are presented each with their own chapters. It was pointed out that the Tab Bar (UITabBarController) is a subclass of UIViewController. Something I never realized before nor questioned. The book also covers how to create custom ViewControllers programmatically and with Interface Builder. Upon completing some of these core chapters involving ViewControllers, UINavigationControllers and UITableViewControllers the reader is left with some great boiler plate code that can be used in future projects. There is really only one correct way to draw table view cells. I am only talking about blank table view cells. Filling those cells with content is going to involve your own custom code. Each of the examples ultimately provide a great starter kit for your own custom iPhone project. There is great chapter devoted to sub-classing the UITableViewCell. It provides some great instructions on how to drop custom view objects on top of the contentView. It’s a recipe on how to develop your very own cell layout that I am going to find useful for my own apps.

When starting out with my first iPhone project I would often times run into this very common road block for newbies. How does one share their model data between multiple view controllers? Chapter 12 (UINavigationController) lays out a great technique that is commonly used by experience iPhone developers. The authors expressed that you should “have all data in the root view controller and only pass subsets of that data to the next UIViewController”. The solution to this problem is really simple and easy to implement. Just pass a property that has been previously set by the model instance. Don’t attempt to load the whole data model for the view controller that needs the data. Feed it only a subset of the data using properties. I am happy the author went over this technique in detail. This piece of advice will certainly be utilized in future iPhone projects.

The most important chapters that I found in the book are the ones that covered persistent storage. The book covers three main ways to save your data via archiving, SQLite, and Core Data. The book offered a rule of thumb when determining which set of “Persistent Mechanisms” to store your data. “If you are dealing with a small amount of data, say, less than a thousand rows, archiving is all you need.” I thought this was a great piece of advise. Why convolute your project with Core Data when ultimately you will only save less than 100 items/rows of data. Keep your app simple and go for the easiest persistent storage solution. There is a great table at the end of chapter 27 that summarizes the pros and cons of archiving, SQLite, and Core Data. Very useful when determining which solution is best for your project. I don’t want to go into great detail on the contents of each chapter. But I’ll be visiting the SQLite chapter quite often to make sure that I am correctly setting up my query correctly to fetch specific rows of data. The chapter on Core Data was very easy to follow and read. The object diagrams that depict the relationships between entities and their attributes was key to understanding how one would layout their entities within the data model in Xcode.

This is one of the best iPhone Programming books in the market. It’s on equal footing with Beginning iPhone 3 Development by Jeff LaMarche and Dave Mark. I highly recommend both books.