Cocoa Programming for Mac OS X - Aaron Hillegass [7]
Each chapter will guide you through the process of adding features to an application. This is not, however, a cookbook. This book teaches ideas, and the exercises show these ideas in action. Don’t be afraid to experiment.
There are about 300 classes in the Cocoa frameworks. All are documented in the online reference (accessed through Xcode’s Help menu). Cocoa programmers spend a lot of time browsing through these pages. But until you understand a lot about Cocoa, it is hard to find the right starting place in your search for answers. As this book introduces you to a new class, look it up in the reference. You may not understand everything you find there, but browsing through the reference will give you some appreciation for the richness of the frameworks. When you reach the end of this book, the reference will become your guide.
Most of the time, Cocoa fulfills the following promise: Common things are easy, and uncommon things are possible. If you find yourself writing many lines of code to do something rather ordinary, you are probably on the wrong track.
Typographical Conventions
To make the book easier to comprehend, we’ve used several typographical conventions.
In Objective-C, class names are always capitalized. In this book, we’ve also made them appear in a monospaced bold font. In Objective-C, method names start with a lowercase letter. Method names will also appear in a monospaced bold font. For example, you might see “The class NSObject has the method dealloc.”
Other literals, including instance variable names that you would see in code, will appear in a regular monospaced font. Also, filenames will appear in this same font. Thus, you might see “In MyClass.m, set the variable favoriteColor to nil.”
Code samples in this book appear in the regular monospaced font. New portions, which you will need to type yourself, will appear in bold.
Common Mistakes
Having watched many, many people work through this material, we’ve seen the same mistakes made hundreds of times. Two mistakes are particularly common: capitalization mistakes and forgotten connections.
Capitalization mistakes happen because C and Objective-C are case-sensitive languages—the compiler does not consider Foo and foo to be the same thing. If you are having trouble making something compile, check to make sure that you have typed all the letters in the correct case.
When creating an application, you will use the Interface Builder editor to connect objects together. Forgotten connections usually allow your application to build and run but result in aberrant behavior. If your application is misbehaving, go back to Interface Builder and check your connections.
It is easy to miss some warnings the first time a file is compiled. Because Xcode does incremental compiles, you may not see those warnings again unless you clean and rebuild the project. If you are stuck, cleaning and rebuilding is certainly worth a try.
How to Learn
All sorts of people come to our class: the bright and the not so bright, the motivated and the lazy, the experienced and the novice. Inevitably, the people who get the most from the class share one characteristic: They remain focused on the topic at hand.
The first trick to maintaining focus is to get enough sleep: ten hours of sleep each night while you are studying new ideas. Before dismissing this idea, try it. You will wake up refreshed and ready to learn. Caffeine is not a substitute for sleep.
The second trick is to stop thinking about yourself. While learning something new, many students will think, “Damn, this is hard for me. I wonder if I am stupid.” Because stupidity is such an unthinkably terrible thing in our culture, the students will then spend hours constructing arguments that explain why they are intelligent yet are having difficulties. The moment you start down this