Disclaimer: I do not generally read programming books from start to finish! Instead, I read them much as I would read a blog that I’ve discovered for the first time, skimming the archives (table of contents), and then taking-in the first few sentences of parts that look interesting to me, and bookmarking posts that I want to read in greater depth (dog-earing pages that deserve a second glance). I almost never go back for those second glances, so basically I have a bunch of programming books laying about that look like they’ve been heavily read, when in fact they’ve hardly been cracked. My excuse is that programming books are so seldom relevant past their publish date that keeping them for reference seems silly. If I’m paging through a book’s contents in search of some solution, it usually means I just don’t know the right search terms. When I find some pages that seem relevant, I then turn to the web with my newfound knowledge, and feel vindicated when I find some piece of web-content that appears (at least at first glance) to be superior and more timely.
I do still tend to keep those books around, however, mostly so I can look through their code examples. I find books that consist of mostly code are almost always more interesting than those that try and teach you some general topic. You can usually find nice code examples on the web, of course, but they are seldom explained in as much detail as you would find in one of these “by example” books. In this case, I have in front of me two books that both attempt to teach some topic, but do so with heavy use of examples. They are hybrids, if you will, of books that teach a general topic, and books that consist of mostly code examples. Maybe all programming books exist on a spectrum with pure thought and abstract theory at one end, and pure code (and more easily out-of-date examples) on the other.
The first of these is Professional iPhone and iPad Database Application Programming, by Patrick Alessi, published by Wiley (Wrox) in 2011. With chapter titles like “Introducing Data-Driven Applications”, “The iPhone and iPad Database: SQLite”, “Displaying Your Data: The UITableView”, and “iPad Interface Elements”, you would definitely not know at first glance that this is an example-driven book. In fact, each of those sections (and all the other sections of the book) run you through the creation of a sample project, each building on knowledge gleaned in the previous chapters. The first chapter includes a very nice introduction to Xcode and shows you how to create a simple
UITableView based application.
The following chapter, “The iPhone and iPad Database: SQLite”, goes a bit farther down the
UITableView rabbit hole with its sample project, and introduces SQLite besides. This chapter definitely endeared me to the author when it said: “While Core Data is the recommended framework for creating data on the iPhone, you may want to forego Core Data and use the SQLite API directly for several reasons.” The author then lists several compelling reasons! This may be a heretical position to take, but avoiding Core Data has always been my preference, although I do occasionally wonder if there are ever good reasons to use Core Data of which I am simply ignorant.
The author does later dedicate five chapters (about a third of the book) to using Core Data, so he can’t think it’s entirely useless. He does not, IMHO, (at least in the cursory skimming I gave that portion of the book), provide any compelling reasons to use Core Data. The closest he comes is when he says (repeatedly) that using the graphical data modeling tool will dramatically speed up the development time of your data driven app. I fail to see how this is the case! If creating your db schema is taking up a lot of your development time, I think you’re probably doing something wrong, or possibly you just aren’t familiar with SQL in general.
(A decent db abstraction layer to handle your
UPDATE etc. calls is also a must, and I am disappointed to report that Alessi’s book does not cover this topic. There is at least one decent open source wrapper available (called FMDB), although there are things I would change about it — namely the API for retrieving your result sets.)
Unfortunately, the portions of the book dedicated to the Core Data modeling tool fall into the “already obsolete” category of coding examples, because they do not appear to cover the Xcode 4 interface. I created a sample project using Core Data to look at the modeling tool, and like Interface Builder, it has been consumed by the “one window” paradigm prevalent in all things Xcode 4. Reading the first couple of chapters on Core Data will probably give you the base knowledge needed to use it anyway, but as I said earlier, google can probably do a better job.
The last third of the book consists of a couple of chapters about integration with web services. This topic makes a lot of sense to include in a book about data-driven applications, but it’s definitely given less attention than the previous two sections. I really think the book should have been expanded quite a bit, both to go into more detail about the stuff it does cover, and also to cover additional stuff that was notably absent. Off the top of my head, here are headings I would have liked to see: best practices for storing data retrieved from web services, how to deal with syncing issues, common tools for consuming web services, and at least one code example for parsing and consuming JSON. Unfortunately, JSON is given only a cursory mention, and its superiority to XML for the task at hand is not, as I feel it it should have been, firmly established.
In the beginning of chapter 10, “Working with XML on the iPhone”, there is a section called Synchronous Data Retrieval, in which some lip service is given to
stringWithContentsOfURL: selector blocking your UI, but then it is not made clear that the subsequent code examples (using
NSURLRequest) are asynchronous in nature! Also, on the topic of “common tools”, the book pretty much writes everything from scratch in this section. I can understand the impulse that the author may have had to explain all the gory details of xml parsing and
NSURLRequests without complicating matters by introducing open source libraries that simplify these processes, but they save far more time than I’m liable to believe you can save by using Core Data. If you are consuming web services from your app, you would be stupid not to use (or at least look at) ASIHTTPRequest. That little project has probably saved me dozens of hours in the last three months. On the subject of XML parsing, the question is not whether you should use an external parser, but rather which XML parser is right for your needs!
Overall, I didn’t expect to read as much of Professional iPhone and iPad Database Application Programming in detail as I ended up reading for this review. I don’t know how much of that was due to wanting to give it a fair read in spite of my bias against using Core Data, and how much was due to the author’s really well written prose. Database applications is about as dry a subject as they come, and yet I never felt lulled to sleep in the way that many programming books have a tendency to do to me. If you are not familiar with SQLite, or programming for
UITableView, I would definitely highly recommend the first four chapters of the book. As for whether they are worth the asking price, (currently $30 on amazon), I’ll leave that up to you.
Unfortunately, I think I’m going to have to leave any in-depth review of my second learn-by-example iOS book for another day: Learning iOS Game Programming: A Hands-On Guide to Building your First iPhone Game, by Michael Daley, published by Addison Wesley in 2011. This book takes you through the author’s process of building an iOS game from start to finish. The game you build, Sir Lamorak’s Quest, is available as a free download from the app store, so you could potentially download it and see if it’s got stuff in it you’d like to know about. I haven’t actually looked at the game for more than a minute or two, but I know from personal experience that parsing through the source code of a game, even one I have no interest in ever making, is always fascinating to me, so I’m quite excited to dig into this book.
Cross-posted on Martin’s dev blog, Chesstris.