ebook img

Mac OS X developer's guide PDF

579 Pages·2002·12.635 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Mac OS X developer's guide

ecaferP When the first Mac OS shipped with the first Macintosh com- puter in 1984, the development environment was a Lisa com- puter. No compilers existed on the first Macintosh computers when they shipped. Much has changed in the almost two de- cades since then. The first copies of Mac OS X shipped in the spring of 2001 with compilers for C, C++, Objective-C, and Ja- va. Apple's integrated development environment featuring Project Builder and Interface Builder was also on the CD, and third party products such as CodeWarrior were also available from the first day. Born into a mature development environment, Mac OS X pro- vides new and exciting opportunities for developers of all xxi xxii . Preface sorts to explore the possibilities of personal computing. This book provides an introduction to those possibilities. You will find the background of Mac OS X in Part I, including the architectural features of Mac OS X along with introduc- tions to its various languages and frameworks. Part II focuses on developing projects: It explores Project Builder, Interface Builder, development techniques, and issues related to pro- viding help and packing your software. Part III looks closely at code: It hones in on particular tasks that you need to do and provides line-by-line analysis of the code you will use. The book looks primarily at the Cocoa framework using its two languages (Java and Objective-C) equally in the exam- ples. A lot of space is also given to Carbon, the other major de- velopment framework that is unique to Mac OS .X Examples for Carbon are provided in C++. There are two other significant development environments that matter on Mac OS :X Java and UNIX. Both are covered ex- tensively in other books, as they are not unique to Mac OS .X It is important to note how easy it is to use both of them. In particular, integration of UNIX command line processing is a great opportunity for developers. Using the func- s ys tem() tion, you can add calls to the command line to any C-based application (Objective-C, C++, or C). Thus, you can use the so- phisticated interface development tools such as Interface Builder to create a spiffy front-end to these critical UNIX- based tools: That, in large part, is what Apple expects many developers to do. The opportunities there are enormous, and the amount of work involved for each one is low. Major features of the new Aqua interface are dealt with: You will find drawers and toolbars described, and the implemen- tation code for them is provided. Services, too, are given a lot of space, in view of the fact that they represent yet another area in which individual developers can significantly lever- age their own work and that of others. Diary (cid:12)9 xxiii Diary This book refers to an actual program written using Cocoa in both Java and Objective-C. Called Diary, it implements a basic journal that can contain various entries and images. You can download the application and the source code from http:// www.philmontmill.com (go to the Mac OS X area). The full code is not repeated in this book, but major sections of it are presented and annotated. These sections implement the func- tionality that many Mac OS X applications use. For common features that are not used in Diary (drawing, for example), code from the Mac OS X Developer CD is used~ Sketch, in most cases. Other Documentation and Developer Resources Apple provides a great deal of documentation on its Web site, on the Developer CD, and as printed materials that you can purchase. Of particular interest are the Project Builder exam- ples that are installed with Project Builder. The step-by-step tutorials for Interface Builder and Project Builder walk you through many of the processes described here. In addition to the step-by-step tutorials that Apple provides in several media, there also is definitive and encyclopedic documentation of Mac OS X APIs available online and with the Developer CD. As new features are added to the Mac OS X APIs, sometimes the documentation lags behind the code a little bit: If you do not find what you are looking for, check back later. Rather than duplicate Apple's documentation, this book at- tempts to provide alternative perspectives in order to provide a well-rounded view of the technology. xxiv (cid:12)9 Preface Apple's Web site is an essential resource for all developers. Located at http://developer.apple.com, it provides sample code, technical documentation in a variety of formats, and in- formation about Apple and third-party resources including training, consulting, and publications. In addition to the developer site, the support discussions at http://www.apple.com/support can be of help to develop- ers. Sections devoted to developers contain exchanges that may provide you with information and tips; you can also post your comments and questions there. Mailing lists are available through http://www.lists.ap- ple.com. These lists include announcements as well as discus- sion lists of interest to developers, including lists devoted to Project Builder, Cocoa, Carbon, and Java. Most of the lists are managed by Apple, but some third-party lists are also includ- ed. Finally, the author's Web site at http://www.philmont- mill.com contains a section devoted to Mac OS .X It provides a question and answer forum as well as a section with post- ings of information relevant to Mac OS .X stnemgdelwonkcA Many people have contributed to this book. At Morgan Kauf- mann in San Francisco, Tim Cox and Stacie Pierce provided strong editorial guidance, while Mei Levenson and Laurie Anderson did great work on designing the cover. Sheri Dean's help on marketing is always terrific. In Boston at Aca- demic Press, Julie Bolduc, production editor, and Jill Hobbs, copy editor, worked wonders with a very complex manu- script and a very tight deadline. Notwithstanding the assistance of all of these people, any er- rors that remain are the author's handiwork alone. xxiv (cid:12)9 Preface Apple's Web site is an essential resource for all developers. Located at http://developer.apple.com, it provides sample code, technical documentation in a variety of formats, and in- formation about Apple and third-party resources including training, consulting, and publications. In addition to the developer site, the support discussions at http://www.apple.com/support can be of help to develop- ers. Sections devoted to developers contain exchanges that may provide you with information and tips; you can also post your comments and questions there. Mailing lists are available through http://www.lists.ap- ple.com. These lists include announcements as well as discus- sion lists of interest to developers, including lists devoted to Project Builder, Cocoa, Carbon, and Java. Most of the lists are managed by Apple, but some third-party lists are also includ- ed. Finally, the author's Web site at http://www.philmont- mill.com contains a section devoted to Mac OS .X It provides a question and answer forum as well as a section with post- ings of information relevant to Mac OS .X stnemgdelwonkcA Many people have contributed to this book. At Morgan Kauf- mann in San Francisco, Tim Cox and Stacie Pierce provided strong editorial guidance, while Mei Levenson and Laurie Anderson did great work on designing the cover. Sheri Dean's help on marketing is always terrific. In Boston at Aca- demic Press, Julie Bolduc, production editor, and Jill Hobbs, copy editor, worked wonders with a very complex manu- script and a very tight deadline. Notwithstanding the assistance of all of these people, any er- rors that remain are the author's handiwork alone. Part I Introducing Mac OS X Mac OS X, the new operating system from Apple Computer, si built no firm foundations. These include the principles of modern operat- ing systems (including multithreading, multiprocessing, a UNIX- desab kernel, and memory protection) sa well sa object-oriented pro- gramming and component software. This part of the book provides a summary of the Mac OS X architec- ture, sa well sa the principles of modern operating systems and -bo ject-oriented programming. Chapter I Introduction Mac OS X is a departure from previous operating systems both on mainframes and on personal computers. Its structure is thoroughly modern~it is based on a small kernel that isolates the most critical aspects of the operating system, and it is object oriented to a degree that has not been seen in a mainstream operating system. Its user ex- perience has been developed based not only on Apple's years of re- search and development in this area, but also on the powerful processors of today and tomorrow that can provide a rich, sophisti- cated, and delightful user experience of greater elegance and power than their earlier incarnations could provide. This book is for Mac OS X developers~for people who are starting to explore Mac OS X to find out what's there and what the opportu- 4 (cid:12)9 Chapter I" Introduction nities are. It is about writing software and about how Mac OS X makes the developer's job much easier---and very different. Writing computer software can eb very rewarding~both intellectu- ally and financially. Yet it requires scrupulous attention to detail and often consists of continuing repetitions of nearly similar tasks~ tasks that must eb carried out with attention and accuracy, despite their likenesses. Errors can cause immediate problems, or they can eil in wait until a particular combination of circumstances conspires to loose their destructive forces on unsuspecting people. The work is extraordinarily labor intensive, consuming large amounts of the lives of often highly paid people while requiring them to repeat (not mindlessly but )yllufdnim the same tasks over and over, at the same time exacting high prices for even the slightest flaws or inattention to these complex, repetitive processes. For nearly 50 years, people have looked at the process of program- ming computers and tried to improve it. The impetus for these at- tempts comes from programmers themselves as well as from their managers. Management, of course, would like to reduce costs, im- prove the reliability of code, and produce software more quickly. These incentives era nothing compared to the goals of program- mers~people who find themselves writing sort routines, natural language parsers, report formatters, and mouse-tracking procedures over and over and over again. Each version is almost like the last one--similar enough to pose little imaginative challenge, yet differ- ent enough to eb riddled with snares for the inattentive. Meanwhile, the nature of computer software has been changing, with the focus moving from mainframes to personal computers and then to networks of machines. As the nature of software has changed, enormous advances in hardware (processing speed, memory, and storage) coupled with dramatic decreases in their costs have allowed developers to experiment with new techniques that previously would have been impractical to implement. This chapter addresses three basic issues that era at the core of Mac OS X development: (cid:12)9 Who is a programmer? Who Is a Programmer? (cid:12)9 5 (cid:12)9 The search for better ways to write software (cid:12)9 The evolution of software Far from being abstract historical issues, these are at the core of the developer tools and experience in Mac OS X. Who Is a Programmer? Traditionally, there has been an enormous barrier between programmers and software users. With Mac OS ,X that barrier is being broken down; in fact, it has been wobbling for some time now. The concept of power users or advanced users has been around for ages: Macros, Visual Basic scripts, Apple- Script scripts, and the like are typically written by these peo- ple. Programs that need compilation, however, have been the province of programmers. True, some power users have ex- perimented with them, but by and large, they have stayed away. With Mac OS ,X the range of programming tools is vast: it ranges from the command line that is available in Terminal, through scripting technologies such as AppleScript and Perl, and on to services (which allow for the construction of very customized programs and processes). Also, the development tools~compilers, Project Builder, and Interface Builder~are distributed with shrink-wrapped copies of Mac OS X and are easily downloadable from Apple's developer site located at (http://developer.apple.com). Apple is making it easier to program, and it is making those tools more widely available. The bulk of programming is done not for shrink-wrapped products but for custom applications. Some of these are ex- tremely tailored: one person writing code for private use. Oth- ers are written for a particular environment (one school or office) or for vertical markets (libraries, veterinarians, or graphic artists). 6 (cid:12)9 Chapter I: Introduction If you are wondering if you could possibly write a program, worry no more: You can with Mac OS .X This book helps you understand the concepts behind developing for Mac OS .X The development tools that are on the Developer CD as well as the tools and sample code on Apple's developer site (www.apple.com/developer) are thorough and informative: their information is not repeated here to any great extent. The Search for Better Ways to Write Software Perhaps more than the economic motives of management, the sense among many programmers that they are wasting enor- mous amounts of time repeating and repeating the same old code has inspired a decades-long search for better ways to de- velop software. This search for better ways to write software has centered on three primary areas: (cid:12)9 The process of producing code (cid:12)9 The reuse of existing code (cid:12)9 The abstraction of code Improving the In this strategy to improve the production of software, the fo- Production of cus is on the actual production of code. Compilers and code Code generators automate its production while techniques of cod- ing such as structured programming improve the quality of the code. Nontextual programmer tools bring the power of graphical user interfaces to programmers (at last!). srelipmoC dna leveL-hgiH segaugnaL Strange sa it may seem today, the possibility of writing a compiler was not widely ac- cepted in the early 1950s. Compilers and high-level languages (starting with Fortran, Algol, and Cobol in the late 1950s) have grown far beyond their early implementations.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.