Cocoa® Programming By Scott Anguish, Erik M Buck, Donald A Yacktman Publisher: Sams Publishing Pub Date: September 20, 2002 ISBN: 0-672-32230-7 Pages: 1272 Copyright About the Authors Acknowledgments We Want to Hear From You! Reader Services Introduction Intended Audience Conventions Learn By Example Part I: Overview Chapter Cocoa and Mac OS X Understanding When to Use Cocoa Understanding Cocoa's Role in Mac OS X What You Need to Use Cocoa What's Included in Cocoa Summary Chapter Cocoa Language Options Object Orientation Java Objective-C Other Languages Choosing a Language for Use with Cocoa The Use of Objective-C in This Book Summary Chapter Using Apple's Developer Tools Obtaining Apple's Developer Tools Project Builder Interface Builder Frameworks Samples Terminal Other Tools Summary Chapter Objective-C Why Learn Objective-C? Additions to C Apple's Extensions The NSObject Base Class Runtime Functions Objective-C++ Summary Chapter Cocoa Conventions Naming Initializers Managing Memory Accessors Using Memory Zones Encoding and Decoding Summary Chapter Cocoa Design Patterns Understanding Design Patterns A Catalog of Cocoa Design Patterns Summary Part II: The Cocoa Frameworks Chapter Foundation Framework Overview Mutability Class Clusters Typed Storage Collections Property Lists Run Loops and Timers Support Types String Processing Bundles File System Access Defaults System Notifications Related Core Foundation Summary Chapter The Application Kit Framework Overview Events and the Run Loop Responders NSApplication Overview NSWindow Overview NSView Overview Delegates Target-Action Paradigm Archived Objects and Nibs NSWindowController Overview Multidocument Applications Undo and Redo Menu Validation Spell Checking Summary Chapter Applications, Windows, and Screens The New Image Viewer Working with NSWindow Working with NSApplication Modal Loops Working with Sheets Working with Drawers Working with Screens Working with Panels Summary Chapter 10 Views and Controls Controls Simple Views and Controls Container Views and Controls Compound Controls Summary Chapter 11 The Cocoa Text System Using the High-Level Text Classes The Text System Architecture Managing Fonts Text Input Summary Chapter 12 Custom Views and Graphics Part I The Quartz Graphics Model Quartz Graphics Via the Application Kit Using the NSBezierPath Class Modifying Drawing Summary Chapter 13 Custom Views and Graphics Part II Using NSGraphicsContext Coordinate System Transformations Drawing Points and Rectangles Optimizing Drawing Summary Chapter 14 Custom Views and Graphics Part III Images and Bitmaps Drawing Text Summary Chapter 15 Events and Cursors Event Handling in Custom NSView Subclasses Managing Cursors Summary Chapter 16 Menus Standard Menu Layouts NSMenu Class NSMenuItem Class Menu Validation Contextual Menus Dock Menus Deprecated Functionality Summary Chapter 17 Color NSColor Class Color Wells Color Panels Customizing the Color Panel NSColorList Class Summary Chapter 18 Advanced Views and Controls NSTableView, NSOutlineView, and NSBrowser Concepts Table Views Outline Views Browsers Combo Boxes Custom Controls Toolbars Status Bars NSQuickDrawView Class Summary Chapter 19 Using Pasteboards Pasteboard Concepts Implementing Cut, Copy, and Paste Implementing Drag and Drop Implementing Services Summary Chapter 20 Adding Online Help Apple Help ToolTips Context-Sensitive Help (NSHelpManager) Summary Chapter 21 Multimedia Sound QuickTime 3D Graphics Summary Chapter 22 Integrating with the Operating System Getting System Information Authentication and Security Communicating with the Workspace Summary Chapter 23 Networking NSURL and NSURLHandle Email Messages Directory Services Interapplication Programming Summary Chapter 24 Subprocesses and Threads Choosing Between Subprocesses and Threads Using the NSTask Class Using the NSThread Class Locking Threading Issues Summary Chapter 25 Printing Basic Printing Overview of the Printing Classes NSView's Printing Support Printing and Pagination Example Printing in NSDocument-Based Applications Summary Part III: Cocoa Techniques Chapter 26 Application Requirements, Design, and Documentation Designing an Application with Requirements Designing TransparentTetris Implementing the Design Using AutoDoc Summary Chapter 27 Creating Custom Frameworks Creating and Using a Framework Header Files Providing Backward Compatibility Debugging Frameworks Summary Chapter 28 Distributing Applications Package Directories Using Disk Images Application Installation Summary Part IV: Appendixes Appendix A Unleashing the Objective-C Runtime Objective-C Objects Messaging with IMPs and Selectors Common Runtime Functions Forwarding, Distributed Objects, and Proxies Examples Summary Appendix B Optimizing and Finding Memory Leaks Optimizing Applications Finding Memory Leaks Summary Appendix C Finding Third-Party Resources Apple-Provided Documentation Example Code Web Sites Mailing Lists Summary Appendix D Cocoa Additions in Mac OS X Version 10.2 Quartz Extreme Handwriting Recognition Address Book and vCard Universal Access Updated Tools Framework Enhancements Summary Index Book: Cocoa® Programming Copyright Copyright © 2003 by Sams Publishing All rights reserved No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher No patent liability is assumed with respect to the use of the information contained herein Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions Nor is any liability assumed for damages resulting from the use of the information contained herein Library of Congress Catalog Card Number: 2001089381 Printed in the United States of America First Printing: September 2002 05 04 03 02 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized Sams Publishing cannot attest to the accuracy of this information Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied The information provided is on an "as is" basis The author(s) and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book Credits Executive Editor Jeff Schultz Acquisitions Editor Betsy Brown Development Editor Susan Hobbs Managing Editor Charlotte Clapp Project Editors Elizabeth Finney Katelyn Cozatt Copy Editor Chip Gardner Indexer Chris Barrick Proofreaders Andrea Dugan Jody Larsen Technical Editors John Ray Steve Munt Team Coordinator Amy Patton Interior Designer Gary Adair Cover Designer Alan Clements Page Layout D&G Limited, LLC software development classes (objects) encapsulation (objects) 2nd inheritance (objects) instances (objects) 2nd 3rd messages (objects) 2nd modularity (objects) polymorphism (objects) 2nd specialization (objects) 2nd sound Core Audio Framework 2nd Core MIDI Framework 2nd NSSound class 2nd 3rd 4th 5th Speech Recognition Manager 2nd Speech Synthesis Manager 2nd source code ***also check code*** Cocoa Programming.net Web site Cocoa samples Apple Developer Web site EDCommon frameworks 2nd MiscHelpManager class 2nd 3rd 4th 5th 6th 7th 8th MiscKit frameworks MOKit frameworks Omni Group frameworks 2nd ToolTipExample Cocoa APIs 2nd 3rd 4th specialization object orientation 2nd Speech Recognition Manager 2nd Speech Synthesis Manager 2nd spell checking Mac OS X version 10.2 split views user interface creating (NSSplitView class) 2nd 3rd 4th 5th delegates (NSSplitView class) square buttons standard locations (files) domains Local 2nd 3rd 4th 5th Network 2nd 3rd 4th 5th System 2nd 3rd 4th 5th User 2nd 3rd 4th 5th states buttons configuring 2nd static typing (Objective-C language) 2nd 3rd static-type checking protocols (Objective-C extensions) 2nd status bars configuring (NSStatusItem class) 2nd creating (NSStatusItem class) 2nd function of limitations of menu-based NSStatusItem class 2nd NSStatusBar class NSStatusItem class removing (NSStatusItem class) view-based NSStatusItem class 2nd StatusItems example source code location steppers configuring (Interface Builder) 2nd 3rd 4th Stepwise Web site Stepwise.com Web site pasteboard resources stopping NSTask class 2nd storing colors NSColor class 2nd IMPS replaced methods (Objective-C runtime) 2nd 3rd 4th 5th streaming media QuickTime features string processing Foundation framework formatters NSCharacterSet class 2nd NSScanner class 2nd regular expressions 2nd strings Foundation framework NSString class 2nd 3rd 4th subclassing NSCell class PieWidget example 2nd 3rd 4th 5th 6th 7th 8th 9th NSControl class PieWidget example 2nd NSTableColumn class 2nd 3rd 4th 5th NSURLHandle class ServerObject subclass (NSThread class) 2nd 3rd 4th 5th 6th 7th 8th 9th submenus attaching to menus 2nd DynamicMenu example adding 2nd subprocesses Unix commands wrapping versus threads selecting 2nd 3rd subviews design patterns application types 2nd Sun Hot Spot JIT compiler super keyword Objective-C 2nd super_class element (Objective-C objects) 2nd support types Foundation framework NSGeometry class 2nd 3rd NSRange class 2nd synchronization threads synchronous downloading NSURL class synchronous tasks NSTask class 2nd 3rd system colors notifications values System domain files location and contents 2nd 3rd 4th 5th tab views user interface adding (NSTabView class) 2nd creating (NSTabView class) 2nd 3rd 4th 5th 6th 7th 8th delegates (NSTabView class) 2nd removing (NSTabView class) 2nd selecting (NSTabView class) 2nd table views columns controlling selectability of (NSTableView class) 2nd columns (NSTableColumn class) 2nd 3rd 4th 5th creating drag and drop pasteboards 2nd 3rd 4th 5th master-detail interface master-detail interfaces implementing (NSDocument class) 2nd 3rd 4th 5th 6th 7th 8th implementing (NSTableView class) 2nd 3rd 4th NSTableView class uses overview 2nd tags controls assigning (NSControl class) 2nd target-actions setting (NSControl class) 2nd 3rd 4th 5th targets/actions design patterns application types 2nd 3rd TaskOutliner example NSOutlineView class delegate methods 2nd optional methods 2nd 3rd required methods 2nd outline views (NSOutlineView class) 2nd TCL scripting language 2nd 3rd tear-off menus 2nd terminating NSTask class 2nd 3rd 4th text appending (NSTextView class) 2nd inserting (NSTextView class) 2nd modifying via controls 2nd 3rd replacing (NSTextView class) 2nd text fields alignment border styles color selection edit field options 2nd user interface configuring 2nd 3rd 4th creating delegates field editor 2nd input managers 2nd secure fields 2nd tab settings 2nd validation 2nd 3rd 4th text system architecture Model-View-Controller (MVC) 2nd 3rd attributed strings implementing 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th initializing 2nd 3rd 4th 5th classes HTML support NSLayoutManager NSParagraphStyle NSTextAttachment NSTextContainer NSTextStorage NSTextView 2nd 3rd 4th 5th 6th 7th RTF support delegate methods NSText class 2nd 3rd 4th 5th NSTextView class 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th fonts common traits and restrictions 2nd 3rd name syntax NSFont class 2nd 3rd 4th 5th 6th 7th NSFontManager class 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th NSFontPanel class 2nd 3rd 4th 5th supported formats formatters NSFormatter class 2nd 3rd input managers NSTextView class 2nd Model-View-Controller (MVC) Control layer 2nd 3rd Model layer 2nd 3rd 4th View layer 2nd 3rd mutable attributed strings implementing 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th overview documentation Apple Developer Web site programmatically end to editing 2nd TextEdit application contextual menus 2nd dock menus 2nd 3rd 4th versus SimpleText application 2nd TextEdit example NSLayoutManager class TextViewConfig example NSLayoutManager class ThreadExample program ServerObject subclass (NSThread class) 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th source code download user interface (NSThread class) 2nd threads critical code sections 2nd deadlock detaching (NSThread class) 2nd function of isolating (Distributed Objects) 2nd issues critical code sections considerations 2nd deadlocks 2nd 3rd 4th 5th debugging 2nd global variables 2nd performance considerations 2nd race conditions locking 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th interthread communication 2nd without blocks 2nd messaging between (NSThread class) 2nd 3rd 4th 5th 6th multiple CPU usage NSConditionLock class locking mechanism 2nd 3rd 4th 5th 6th NSDistributedLock class locking mechanism 2nd 3rd NSLock class locking mechanism 2nd NSRecursiveLock class NSThread class 2nd ThreadExample program 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th race conditions serialized 2nd synchronization versus NSTimers class 2nd versus subprocesses selecting 2nd 3rd tick marks sliders configuring (NSSlider class) 2nd timers Foundation framework NSTimer class 2nd tinting controls PieWidget example 2nd titles boxes sliders drawing (NSSlider class) ToolbarExample source code location 2nd toolbars creating 2nd 3rd NSToolbar class 2nd 3rd 4th 5th delegate creation 2nd 3rd 4th 5th item validation 2nd NSToolbarItem class 2nd instance configuration 2nd item identifiers 2nd ToolTipExample program source code (Cocoa APIs) 2nd 3rd 4th ToolTips (help) appearance of Cocoa APIs setting 2nd 3rd 4th 5th limitations (Interface Builder) NSHelpManager class help methods 2nd NSView class help methods 2nd 3rd 4th 5th setting (Interface Builder) 2nd transmitting data NSTask class object 2nd transparent windows Image Viewer application type encoding Objective-C extensions 2nd UFS (Unix File System) 2nd Uniform Resource Locators, [See URLs] universal access Mac OS X version 10.2 2nd University of California-Berkeley BSD of Unix Unix BSD component Mac OS X enhancements Mac OS X roots 2nd URLs (Uniform Resource Locators) canonical syntax components NSURL class instance creation 2nd 3rd 4th NSURLHandle class RFC 2396 Usenix Organization Web site User domain files location and contents 2nd 3rd 4th 5th user interface Animal example (NSTask class) 2nd 3rd buttons behavior configuration 2nd configuring 2nd 3rd creating 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th key equivalents rendering 2nd 3rd state configuration 2nd Calendar example (NSTask class) 2nd 3rd ClassBrowser example master-detail relationship 2nd multiple column browser implementation 2nd 3rd 4th 5th 6th 7th 8th 9th 10th single column browser implementation 2nd 3rd 4th containers boxes 2nd 3rd 4th 5th 6th 7th 8th 9th controls 2nd scroll views 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th split views 2nd 3rd 4th 5th 6th tab views 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th views 2nd data sources lazy loading 2nd hierarchical data tree structure 2nd images displaying 2nd 3rd 4th 5th 6th NSBrowser class 2nd 3rd 4th 5th 6th configuring (Interface Builder) 2nd 3rd 4th NSOutlineView class 2nd 3rd 4th NSTableView class 2nd 3rd 4th progress indicators creating 2nd 3rd 4th 5th 6th 7th determinate indeterminate selection considerations 2nd 3rd sliders creating 2nd 3rd 4th ranges rendering sizing 2nd tick marks 2nd titles text fields alignment border styles color selection configuring 2nd 3rd 4th creating delegates edit field options 2nd field editor 2nd input managers 2nd secure fields 2nd tab settings 2nd validation 2nd 3rd 4th ThreadExample program (NSThread class) 2nd user interfaces color panels dragging colors (Interface Builder) 2nd color panels (Interface Builder) 2nd 3rd 4th 5th color wells (Interface Builder) 2nd 3rd controls customizing 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th fonts NSFontManager class 2nd users operating systems identifying privileges 2nd set uid applications security vulnerabilities 2nd validating menus 2nd 3rd 4th MYDocumentManager class menus service menus pasteboards 2nd text fields user interfaces 2nd 3rd 4th values controls setting (NSControl class) 2nd 3rd 4th Foundation framework NSValue class 2nd 3rd 4th 5th vCards Address Book applciation (Mac OS X version 10.2) 2nd vending distributed objects interapplication communication 2nd 3rd 4th 5th 6th 7th 8th 9th 10th version element (Objective-C objects) versions frameworks setting 2nd View layer application design pattern 2nd text system classes 2nd 3rd W3C Web site commentary from Tim Berners-Lee Web browsers Berners-Lee development QuickTime support Web links inserting (NSAttributedString class) 2nd Web sites 3D Labs AAA+ Software Apple class cluster documentation Apple Darwin Open Source Apple Developer 2nd 3rd Apple Events documentation authentication/authorization documentation Carbon Authorizattion Services API drawer documentation 2nd encoding constants input manager documentation layout managers 2nd localized strings information Mach messages/ports resources modal loop documentation Model-View-Controller (MVC) NSFileHandle class resources NSFont class documentation NSFormatter class tutorial NSScreen class NSTextView class documentation optimization resources text system documentation transparent windows sample Apple Developers Core Audio/Core MIDI Framework documentation OpenGL 3D sample applications Quick Time API references/samples speech resources 2nd spound playing resources Cocoa Programming.net 2nd Animal example source code Calendar source code DockMenu example DynamicMenu example 2nd LotsOfWords application source code PaginationDemos example 2nd source code examples ThreadExample download CocoaDev CocoaProgramming.net Cris.com F-Script GCC (GNU Compiler Collection) 2nd Gnustep Project GNUstep.org IMC.org vCard resources 2nd LowTek sockets documentation MacTech MiscKit MOKIt Montage Tech Mulle-Kybernetik 2nd Mulle-Kybernetik.com Music Kit Omni Group 2nd 3rd OÕReilly Mac DevCenter OpenGL.org RubyCocoa Project Softrak Stepwise Usenix Organization W3C widgets [See also controls] interactive 2nd passive 2nd window frames Image Viewer saving in user defaults 2nd windows configuring (MYDocument class) 2nd 3rd 4th Image Viewer transparent Windows TrueType fonts text system support workspace communication with 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th elements NSWorkspace class 2nd information retrieval 2nd 3rd 4th 5th 6th operations requests 2nd 3rd 4th 5th 6th 7th 8th 9th 10th workspaces MYWorkspaceNotificationObserver class 2nd 3rd 4th 5th wrapping Unix commands subprocesses writing data pasteboards 2nd 3rd 4th ... Book: Cocoa Programming Part I: Overview IN THIS PART Cocoa and Mac OS X Cocoa Language Options Using Apple's Developer Tools Objective-C Cocoa Conventions Cocoa Design Patterns Book: Cocoa Programming. .. Overview Chapter Cocoa and Mac OS X IN THIS CHAPTER ● ● ● ● Understanding When to Use Cocoa Understanding Cocoa' s Role in Mac OS X What You Need to Use Cocoa What's Included in Cocoa Cocoa is a collection... from Sams Publishing, visit our Web site at www.samspublishing.com Type the ISBN (excluding hyphens) or the title of the book in the Search box to find the book you're looking for Book: Cocoa Programming