Building iPhone Apps, Part I: Cocoa and Objective-C

This past summer, I decided I wanted to get into app programming. I have an ipod touch and a first generation ipad, my wife had just gotten an iphone, and – much as I dislike Apple – I had to admit that all these gadgets were pretty nifty! I just had three main problems:

  1. I hadn’t used C in years, and I never did much with memory management.
  2. I knew absolutely nothing about Cocoa or Objective-C, and very little about hardware programming.
  3. I can’t stand Apple computers.

Still, we have a mac mini (my wife, a dedicated Apple fangirl, talked me into it with the perfectly reasonable argument that as a web designer, she needed to be able to test her sites on a mac as well as a PC) and I do occasionally end up with a few minutes of free time, so I decided to learn. I’ve been using these four books:

(Why the hacking book? I’ll cover that in a later review)

The primary books here are the Head First guide (the first book I’ve read in that series, incidentally) and the Cocoa book. The goal of the Head First guide is simple: it walks you through building simple apps without overwhelming you with too much detail so you can get experience programming and have the satisfaction of building something that works. As someone with programming experience, though, I wanted more technical details on the code, which is where the Cocoa book comes in.

My learning method was simple: I’d work through the Head First guide for a while, then when I got tired of being annoyed at the mac I’d switch to reading the Cocoa book. (As with most computer books it’s really meant to be read in front of a computer, typing in code, but it’s also written to be accessible to people without programming experience). Here’s how the book works:

Chapter one is an introduction: here’s how you download and set up Xcode, Apple’s development environment, and create an extremely simple app with it. The next section is an introduction to C, which can be skipped by anyone who’s already familiar with C and object-oriented programming: it covers basic C, memory and pointers, and using objects. Chapters five and six then introduce Objective-C, which has been described as ‘C with objects’; it is a superset of C that adds in object-oriented features from Smalltalk. Although Objective-C was created nearly 30 years ago, its primary use now is as the main language used with Cocoa, Apple’s API for Mac and iOS applications.

In chapter 7, we start learning about classes used in Cocoa; while not as efficient as C types, they offer safeguards and abstraction, making it easier to write your program and keep it secure. Here we learn about those classes and how to decide which ones to use. All of this comes from the Foundation framework, one of the three frameworks imported by Cocoa.h.

So far, we could have been writing any kind of program; there’s nothing that deals specifically with apps. In chapter 8, we get into the Appkit user interface, which provides built-in controls (and ways to build custom controls) that provide the look and feel of your app. Finally, in chapter 9 we get to the mindset behind mac and iPhone programming: the Model-View-Controller layout, or MVC. The MVC tells you how your classes will talk to each other; every app uses it to pass data around.

If there’s one thing that Apple is known for, it’s graphics; artistic people tend to like Macs. Chapter 10 discusses the main graphics and animation frameworks that you’ll use to make sure your app looks good, then walks you through making custom views with the AppKit classes.

That pretty much wraps up the book; chapter 11 is just a few pages of tips on becoming an app programmer and links to useful Cocoa sites. This book will get you started with Cocoa programming, but it obviously won’t make you an expert; this can help you find where to go next.

Overall, I found the book to be quite readable; I got through one of the early chapters while on a plane to New Orleans. If you’re already familiar with C, the structure makes it easy to jump right to where you need to be, while those who haven’t used it before or need a refresher can get one by reading through the beginning. On the other hand, if you already understand Objective-C, this probably isn’t the book you want to learn Cocoa, as you’ll end up skipping nearly half of it to get to the Cocoa sections.

Overall? I’ve actually enjoyed reading from a programming book, and if you think that sounds like a recommendation, you’re right.

So what kind of app did I build? Stay tuned for part two..

Disclosure: IĀ receivedĀ a free review copy of this book.

Share Button
Google+

Tags:

This entry was posted by William on Tuesday, December 20th, 2011 at 10:21 pm and is filed under Technical . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply