logo资料库

Learning Cocoa with Objective C.pdf

第1页 / 共461页
第2页 / 共461页
第3页 / 共461页
第4页 / 共461页
第5页 / 共461页
第6页 / 共461页
第7页 / 共461页
第8页 / 共461页
资料共461页,剩余部分请下载后查看
Table of contents
Copyright
Preface
Audience
About the Example Code
How This Book Is Organized
How to Use This Book
Conventions Used in This Book
How to Contact Us
Acknowledgments
Part I: Cocoa Overview and Foundation
Chapter 1. Introduction to Cocoa
1.1 The Mac OS X Programming Environment
1.2 Cocoa Defined
1.3 The Cocoa Frameworks
1.4 Languages
1.5 The Foundation Framework
1.6 The Application Kit Framework
Chapter 2. Cocoa Development Tools
2.1 Installing the Developer Tools
2.2 Interface Builder
2.3 Other Tools
2.4 Exercises
Chapter 3. Object-Oriented Programming with Objective-C
3.1 Introducing Objects
3.2 Creating and Using Objects
3.3 Methods and Messages
3.4 Objective-C-Defined Types
3.5 Creating New Classes
3.6 Overriding Methods
3.7 Other Concepts
3.8 Exercises
Chapter 4. The Cocoa Foundation Kit
4.1 Strings
4.2 Collections
4.3 Memory Management
4.4 Exercises
Part II: Single-Window Applications
Chapter 5. Graphical User Interfaces
5.1 Graphical User Interfaces in Cocoa
5.2 Designing Applications Using MVC
5.3 Create the Currency Converter Project
5.4 Create the Interface
5.5 Define the Classes
5.6 Connect the Model, Controller, and View
5.7 Implement the Classes
5.8 Build and Run
5.9 Exercises
Chapter 6. Windows, Views, and Controls
6.1 Windows and the Window System
6.2 The View Hierarchy
6.3 Coordinate Systems
6.4 Controls, Cells, and Formatters
6.5 Targets and Actions
6.6 Exercises
Chapter 7. Custom Views
7.1 Custom View Creation Steps
7.2 Create a Custom View
7.3 Drawing into a View: Behind the Scenes
7.4 Draw Strings into a View
7.5 Draw Paths into a View
7.6 Exercises
Chapter 8. Event Handling
8.1 Events
8.2 Dot View Application
8.3 Event Delegation
8.4 Notifications
8.5 Exercises
Chapter 9. Models and Data Functionality
9.1 Protocols
9.2 Key-Value Coding
9.3 Table Views
9.4 Table View Example
9.5 Saving Data: Coding and Archiving
9.6 Using Formatters
9.7 Sorting Tables
9.8 Exercises
Part III: Document-Based Applications
Chapter 10. Multiple Document Architecture
10.1 Architectural Overview
10.2 Building a Document-Based Application
10.3 Exercises
Chapter 11. Rich-Text Handling
11.1 Cocoa's Text System
11.2 Creating a Rich-Text Editor
11.3 Enabling the Font Menu
11.4 Text Storage and Attributed Text
11.5 Enabling the Text Menu
11.6 Handling Embedded Images
11.7 Exercises
Part IV: Miscellaneous Topics
Chapter 12. Printing
12.1 Printing a View
12.2 Using Print Operations
12.3 Setting Margins
12.4 Exercises
Chapter 13. Bundles and Resources
13.1 Peeking Inside Bundles
13.2 Using Bundles
13.3 Exercises
Chapter 14. Localization
14.1 Mac OS X Language Preferences
14.2 Localizing Resources
14.3 Localizing Nib Files
14.4 Localizing Strings
14.5 Exercises
Chapter 15. Defaults and Preferences
15.1 How Preferences Work
15.2 Using Defaults
15.3 Command-Line Preferences Access
15.4 Using Unique Application Identifiers
15.5 Exercises
Chapter 16. Accessory Windows
16.1 The Role of File's Owner
16.2 Making an Info Window
16.3 Exercises
Chapter 17. Finishing Touches
17.1 Tidying Up the User Interface
17.2 Providing an Icon
17.3 Providing Help
17.4 Customizing the About Box
17.5 Tweaking Compiler Settings
17.6 Packaging for Distribution
17.7 Closure
17.8 Exercises
Part V: Appendixes
Appendix A. Exercise Solutions
A.1 Chapter 2
A.2 Chapter 3
A.3 Chapter 4
A.4 Chapter 5
A.5 Chapter 6
A.6 Chapter 7
A.7 Chapter 8
A.8 Chapter 9
A.9 Chapter 10
A.10 Chapter 11
A.11 Chapter 12
A.12 Chapter 13
A.13 Chapter 14
A.14 Chapter 15
A.15 Chapter 16
A.16 Chapter 17
Appendix B. Additional Resources
B.1 Documentation on Your Hard Drive
B.2 Printed Documentation
B.3 Getting Sample Code
B.4 Web Sites
B.5 Mailing Lists
B.6 Partnering with Apple
Appendix C. Using the Foundation and Application Kit API References
C.1 Cocoa Browser
Colophon
Index
Learning Cocoa with Objective-C By Apple Computer, Inc. , James Duncan Davidson Publisher: O'Reilly Pub Date: September 2002 ISBN: 0-596-00301-3 Pages: 382 • Reviews • Examples • Reader Reviews • Errata Copyright Preface Audience About the Example Code How This Book Is Organized How to Use This Book Conventions Used in This Book How to Contact Us Acknowledgments Part I: Cocoa Overview and Foundation Chapter 1. Introduction to Cocoa Section 1.1. The Mac OS X Programming Environment Section 1.2. Cocoa Defined Section 1.3. The Cocoa Frameworks Section 1.4. Languages Section 1.5. The Foundation Framework Section 1.6. The Application Kit Framework Chapter 2. Cocoa Development Tools Section 2.1. Installing the Developer Tools Section 2.2. Interface Builder Section 2.3. Other Tools Section 2.4. Exercises Chapter 3. Object-Oriented Programming with Objective-C Section 3.1. Introducing Objects Section 3.2. Creating and Using Objects Section 3.3. Methods and Messages Section 3.4. Objective-C-Defined Types Section 3.5. Creating New Classes
Section 3.6. Overriding Methods Section 3.7. Other Concepts Section 3.8. Exercises Chapter 4. The Cocoa Foundation Kit Section 4.1. Strings Section 4.2. Collections Section 4.3. Memory Management Section 4.4. Exercises Part II: Single-Window Applications Chapter 5. Graphical User Interfaces Section 5.1. Graphical User Interfaces in Cocoa Section 5.2. Designing Applications Using MVC Section 5.3. Create the Currency Converter Project Section 5.4. Create the Interface Section 5.5. Define the Classes Section 5.6. Connect the Model, Controller, and View Section 5.7. Implement the Classes Section 5.8. Build and Run Section 5.9. Exercises Chapter 6. Windows, Views, and Controls Section 6.1. Windows and the Window System Section 6.2. The View Hierarchy Section 6.3. Coordinate Systems Section 6.4. Controls, Cells, and Formatters Section 6.5. Targets and Actions Section 6.6. Exercises Chapter 7. Custom Views Section 7.1. Custom View Creation Steps Section 7.2. Create a Custom View Section 7.3. Drawing into a View: Behind the Scenes Section 7.4. Draw Strings into a View Section 7.5. Draw Paths into a View Section 7.6. Exercises Chapter 8. Event Handling Section 8.1. Events
Section 8.2. Dot View Application Section 8.3. Event Delegation Section 8.4. Notifications Section 8.5. Exercises Chapter 9. Models and Data Functionality Section 9.1. Protocols Section 9.2. Key-Value Coding Section 9.3. Table Views Section 9.4. Table View Example Section 9.5. Saving Data: Coding and Archiving Section 9.6. Using Formatters Section 9.7. Sorting Tables Section 9.8. Exercises Part III: Document-Based Applications Chapter 10. Multiple Document Architecture Section 10.1. Architectural Overview Section 10.2. Building a Document-Based Application Section 10.3. Exercises Chapter 11. Rich-Text Handling Section 11.1. Cocoa's Text System Section 11.2. Creating a Rich-Text Editor Section 11.3. Enabling the Font Menu Section 11.4. Text Storage and Attributed Text Section 11.5. Enabling the Text Menu Section 11.6. Handling Embedded Images Section 11.7. Exercises Part IV: Miscellaneous Topics Chapter 12. Printing Section 12.1. Printing a View Section 12.2. Using Print Operations Section 12.3. Setting Margins Section 12.4. Exercises Chapter 13. Bundles and Resources Section 13.1. Peeking Inside Bundles Section 13.2. Using Bundles
Section 13.3. Exercises Chapter 14. Localization Section 14.1. Mac OS X Language Preferences Section 14.2. Localizing Resources Section 14.3. Localizing Nib Files Section 14.4. Localizing Strings Section 14.5. Exercises Chapter 15. Defaults and Preferences Section 15.1. How Preferences Work Section 15.2. Using Defaults Section 15.3. Command-Line Preferences Access Section 15.4. Using Unique Application Identifiers Section 15.5. Exercises Chapter 16. Accessory Windows Section 16.1. The Role of File's Owner Section 16.2. Making an Info Window Section 16.3. Exercises Chapter 17. Finishing Touches Section 17.1. Tidying Up the User Interface Section 17.2. Providing an Icon Section 17.3. Providing Help Section 17.4. Customizing the About Box Section 17.5. Tweaking Compiler Settings Section 17.6. Packaging for Distribution Section 17.7. Closure Section 17.8. Exercises Part V: Appendixes Appendix A. Exercise Solutions Section A.1. Chapter 2 Section A.2. Chapter 3 Section A.3. Chapter 4 Section A.4. Chapter 5 Section A.5. Chapter 6 Section A.6. Chapter 7 Section A.7. Chapter 8
Section A.8. Chapter 9 Section A.9. Chapter 10 Section A.10. Chapter 11 Section A.11. Chapter 12 Section A.12. Chapter 13 Section A.13. Chapter 14 Section A.14. Chapter 15 Section A.15. Chapter 16 Section A.16. Chapter 17 Appendix B. Additional Resources Section B.1. Documentation on Your Hard Drive Section B.2. Printed Documentation Section B.3. Getting Sample Code Section B.4. Web Sites Section B.5. Mailing Lists Section B.6. Partnering with Apple Appendix C. Using the Foundation and Application Kit API References Section C.1. Cocoa Browser Colophon Index
Book: Learning Cocoa with Objective-C Copyright © 2002, 2001 O'Reilly & Associates, Inc. All rights reserved. Printed in the United States of America. Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O'Reilly & Associates books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safari.oreilly. com). For more information contact our corporate/institutional sales department: 800-998- 9938 or corporate@oreilly.com. Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly & Associates, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly & Associates, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. The association between the image of an Irish setter and the topic of Cocoa is a trademark of O'Reilly & Associates, Inc. Apple Computer, Inc. boldly combined open source technologies with its own programming efforts to create Mac OS X, one of the most versatile and stable operating systems now available. In the same spirit, Apple has joined forces with O'Reilly & Associates to bring you an indispensable collection of technical publications. The ADC logo indicates that the book has been technically reviewed by Apple engineers and is recommended by the Apple Developer Connection. Apple, the Apple logo, AppleScript, AppleTalk, AppleWorks, Carbon, Cocoa, ColorSync, Finder, FireWire, iBook, iMac, iPod, Mac, Mac logo, Macintosh, PowerBook, QuickTime, QuickTime logo, Sherlock, and WebObjects are trademarks of Apple Computer, Inc., registered in the United States and other countries. The "keyboard" Apple logo ( with permission of Apple Computer, Inc. ) is used While every precaution has been taken in the preparation of this book, the publisher and the author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
Book: Learning Cocoa with Objective-C Preface Like a finely tuned BMW, Mac OS X is the ultimate programming machine. Under the hood lies a powerful Unix engine, named Darwin, developed via Apple's open source initiative and based on FreeBSD 4.4 and the Mach 3.0 microkernel. On the outside is a highly polished graphical user interface (GUI) whose usability can't be touched by any desktop environment on the planet, including GNOME and KDE for Linux, as well as Windows XP. The newest cat on the block-Mac OS X 10.2 (code-named Jaguar)-takes desktop and network computing to a new level. Jaguar, first introduced to developers as a pre-Alpha release at Apple's Worldwide Developer Conference (WWDC) in May 2002 and later released to the public on August 24, 2002, brings many changes and improvements to the legacy set forth by the previous Mac OS X releases. These changes include several additions to the Cocoa application programming interfaces (APIs), known as the Cocoa frameworks, arguably the best GUI application development environment on the face of the planet. An integrated set of libraries and runtime, Cocoa provides a rich infrastructure on which to build great user applications. On Codenames and Cats As mentioned earlier, Mac OS X 10.2 was code-named Jaguar during its development and testing phase. Earlier releases of Mac OS X included Puma (Mac OS X 10.1) and Cheetah (Mac OS X 10.0). Software developers like to give their projects names that evoke some emotion or theme for the release being worked on. A little research shows that the cheetah is the world's fastest land mammal, while the jaguar, unlike many other big cats, has no predators save for man. Worthy goals indeed. Apple became so enamored of the Jaguar name that they ended up putting it onto the box in which Mac OS X 10.2 is released, complete with a jaguar fur motif. When it comes to building Cocoa applications, developers can choose from three languages to work with the Cocoa APIs: Objective-C, Java, and AppleScript. This new edition of Learning Cocoa, retitled as Learning Cocoa with Objective-C and thoroughly revised and updated for Jaguar, shows you how to get started with building Cocoa applications for Mac OS X using the Objective-C binding to the Cocoa frameworks.
As an introductory book on Cocoa development, Learning Cocoa with Objective-C accomplishes the following: l Introduces you to the concepts of object-oriented programming with Objective-C l Shows you how to use Apple's Developer Tools, in particular, Project Builder and Interface Builder l Introduces you to Cocoa's frameworks-Foundation and the Application Kit-by having you build simple applications along the way The concepts learned in one chapter spill over to the next, and the sample programs you build while reading along get more complex as you go deeper into the book. By the end of the book, you will have learned enough about Cocoa and Objective-C to set you on your way to higher learning, and for that, there are plenty of other books available: l Building Cocoa Applications: A Step-by-Step Guide, by Simson Garfinkel and Michael K. Mahoney (O'Reilly & Associates, Inc.) l Cocoa Programming for Mac OS X, by Aaron Hillegass (Addison-Wesley) l Cocoa Programming, by Scott Anguish, Erik Buck, and Donald Yacktman (Sams) While these books also deal with Cocoa programming with Objective-C, each book takes a slightly different approach. Programming is a funny art, and sometimes it is invaluable to see several approaches to the same subject matter. To be a true master of the craft, you'll probably want to read each of these books and glean from each what you can.[1] In addition to this and the previously listed books, you also have a vast resource of information at your fingertips in the form of Apple's own documentation. Installed on your system along with the Developer Tools, Apple's docs can be found in /Developer / Documentation in both PDF and HTML format. If you have a fast or constant link to the Internet, you can save some space on your hard drive by dumping these docs in the Trash and using the online documentation found at http://developer.apple.com. When Apple updates their documentation, they often first post the revisions online, so you might want to keep that URL handy. Additionally, there are some online resources-mailing lists and web sites-that you should subscribe to and read frequently. A listing of these resources can be found in Appendix B, located at the back of this book. [1] Learn the ways of the Force, Luke-just stay away from the Dark Side.
分享到:
收藏