Cocoa Programming for Mac OS X - Aaron Hillegass [5]
For many years, Apple Computer had been working to develop an operating system with many of the features of NeXTSTEP. This effort was known as Copland. Project Copland gradually spun out of control, and Apple finally decided to pull the plug and buy the next version of Mac OS from another company. After surveying the existing operating systems, Apple selected NeXTSTEP. Because NeXT was small, Apple simply bought the whole company in December 1996.
NeXTSTEP became Mac OS X. It is Unix underneath, and you can get all the standard Unix programs (such as the Apache Web server) on Mac OS X. It is extremely stable and the user interface is spectacular.
In 2008, the iOS SDK, as it would eventually be called, was announced. Apple’s incredibly successful App Store has brought an audience of millions to iOS developers, many of whom are also Cocoa developers on the Mac. Cocoa Touch is built on top of the very same foundations as Cocoa, and indeed many of the classes are identical. More important, the principles and design patterns are essentially unchanged. In 2010, just ahead of Mac OS X Lion, Apple introduced the Mac App Store, bringing the same ease of distribution to Mac developers.
You, the developer, are going to love Mac OS X because Cocoa will enable you to write full-featured applications in a radically more efficient and elegant manner.
Tools
You will love Cocoa but perhaps not immediately. First, you will learn the basics. Let’s start with the tools that you will use.
All the tools for Cocoa development come as part of the Mac OS X Developer Tools, and you get them for free with Mac OS X. Although the Developer Tools will add about a dozen handy applications to your system, you will use one application primarily: Xcode. Behind the scenes, either the LLVM (Low Level Virtual Machine) or the GNU C compiler (gcc) will be used to compile your code, and the GNU debugger (gdb) or the LLDB (Low Level Debugger) will help you find your errors.
Xcode tracks all the resources that will go into an application: code, images, sounds, and so on. You will edit your code in Xcode, and Xcode can compile and launch your application. Xcode can also be used to invoke and control the debugger. We strongly recommend using Xcode 4.2 or greater when trying the exercises in this book. While many of the concepts covered can be applied in the Xcode 3 and even earlier, the style of memory management used (ARC) requires the Xcode 4.2 compiler.
Inside Xcode, you will use the Interface Builder editor as a GUI builder. It edits XIB files, allowing you to lay out windows and add widgets to those windows. It is, however, much more. Interface Builder allows the developer to create objects and edit their attributes. Most of those objects are UI elements such as buttons and text fields, but some will be instances of classes that you create.
You will also use Instruments to profile your application’s CPU, memory, and filesystem usage. Instruments can also be used to debug memory-management issues. Instruments is built on top of dtrace, which makes it possible to create new instruments.
Language
This book uses Objective-C for all the examples. Objective-C is a simple and elegant extension to C, and mastering it will take about two hours if you already know C and an object-oriented language such as Java or C++.
It is possible to develop Cocoa applications in Ruby or Python. This book will not cover that technique,