Cocoa Programming for Mac OS X (3rd Edition)

Cocoa Programming for Mac OS X (3rd Edition)

By Aaron Hillegass

If you're developing applications Mac OS X, Cocoa Programming for Mac OS X, Third Edition, is the book you've been waiting to get your hands on. If you're new to the Mac environment, it's probably the book you've been told to read first. Covering the bulk of what you need to know to develop full-feature applications for OS X, written in an engaging tutorial style, and thoroughly class-tested to assure clarity and accuracy, it is an invaluable resource for any Mac Programmer.

Specifically, Aaron Hillegass introduces the three most commonly used Mac developer tools: Xcode, Interface Builder, and Instruments. He also covers the Objective-C language and the major design patterns of Cocoa. Aaron illustrates his explanations with exemplary code, written in the idioms of the Cocoa community, to show you how Mac programs should be written. After reading this book, you will know enough to understand and utilize Apple's online documentation for your own unique needs. And you will know enough to write your own stylish code.

Book Notes

Important note: If you are using Xcode 3.1, the NIB file format has been replaced in the template projects with XIB files. They work the same. (Well, really XIB is a nice readable XML format that gets converted to a NIB at compile time. But the differences are not important when you are using them.)

Cocoa Programming for Mac OS X assumes that you already know C and something about objects. If you don't know C, there are several good books on it. My favorite book on C is C Programming by King, but some readers complain that it is too expensive. The classic book is "The C Programming Language" by K + R.

If you don't know objects, you should probably get started with a book on Objective-C. There are two: Dalrymple's book is a short and pleasant read. Steve Kochan's is longer.


Chapter 28: As of Aug 15, 2009, Amazon requires that all requests be signed. Thus, this exercise doesn't work any more. The workaround is pretty extreme: You need to create your own AWS account to get a private key and then sign your request as explained on this page.

Page 106: I used deprecated API here. It should be:

[tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:defaultRow] byExtendingSelection:NO];

Using the book with Xcode 3.2: If you are trying to use the book with the Xcode that ships with Snow Leopard, you will notice that the project templates have changed. If you create a Cocoa Application project called Foo, a class calledFooAppDelegate will be created and one instance of that class will be created in the MainMenu.xib file. Just delete FooAppDelegate.h and FooAppDelegate.m from the project and delete the instance before continuing with the book. I think that you should have no more trouble. (Most of the exercises have a class called AppController, FooAppDelegate is designed to take on the same role.

One more thing: On Snow Leopard, many of the delegate methods are now declared as protocols (using the new @optional keyword introduced in ObjC 2.0). As a result, you may get a warning like "AppController does not implement the NSSpeechSynthesizerDelegate protocol". To fix this, just specify that your class does conform to the protocol in the declaration of the class:

@interface AppController: NSObject


One of the challenges of writing a technical book is that technology changes, often rapidly. In the case of the Cocoa book, Amazon changed its web service. To remedy that situation, here is a supplement for the affected chapters: Cocoa 3rd Edition Supplement.