ebook img

Beginning Mac OS X Snow Leopard Programming PDF

651 Pages·2010·35.06 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 Beginning Mac OS X Snow Leopard Programming

BEGINNING Mac OS® X Snow Leopard™ Programming Michael Trent and Drew McCormack ffffiirrss..iinndddd iiiiii 1122//1122//0099 11::5588::0022 PPMM Beginning Mac OS® X Snow Leopard™ Programming Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-57752-3 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifi cally disclaim all warranties, including without limitation warranties of fi tness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: 2009940871 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other countries, and may not be used without written permission. Mac OS and Snow Leopard are trademarks or registered trademarks of Apple, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. ffffiirrss..iinndddd iivv 1122//1122//0099 11::5588::0033 PPMM CONTENTS PART I: MAC OS X DEVELOPER RESOURCES CHAPTER 1: THE MAC OS X ENVIRONMENT 3 Introducing the Mac OS X 4 The Core Operating System 6 The Kernel 8 The System Library 9 Unix Commands 9 Graphics and Media Layers 12 The Quartz Compositor 12 Quartz 2D 15 OpenGL 15 QuickTime 15 Core Animation 16 Application Frameworks and UI 16 Cocoa 17 Carbon 17 Java JDK 18 Apple Human Interface Guidelines 19 Summary 20 CHAPTER 2: DEVELOPER TOOLS 23 Installing the Developer Software 23 Developer Applications 24 Build Tools 24 Performance Tools 24 Other Utilities 31 Command-Line Tools 36 Developer Documentation and Examples 39 Conceptual Documentation 40 API Reference 43 Examples 44 Man Pages 45 ffttoocc..iinndddd iixx 1122//1155//0099 33::2233::3322 PPMM CONTENTS Apple Developer Connection 46 Documentation 47 Examples 48 Mailing Lists 49 Developer Tools 49 Developer Support 50 Summary 50 CHAPTER 3: XCODE 53 Starting a New Project 54 Working with Files 58 Writing Your Code 63 A Second Look at Indenting 69 Building and Running 71 Finding Problems with the Static Analyzer 75 Using the Debugger 78 Online Documentation 85 Summary 92 CHAPTER 4: INTERFACE BUILDER 95 Starting a New Interface 96 Building Menus 99 Building Windows 102 Making Windows Resizable 108 Summary 112 PART II: APPLICATION PROGRAMMING CHAPTER 5: THE APPLICATION 117 Basic Bundle Structure 118 Opaque Directory 118 Versioned Bundles 119 The Info.plist File 120 Executable Code 122 Global Resources 122 Localized Resources 122 Examining Application Bundles 123 Building an Application Bundle 127 Application Preferences 137 Summary 142 x ffttoocc..iinndddd xx 1122//1155//0099 33::2233::3333 PPMM CONTENTS CHAPTER 6: THE C LANGUAGE 145 A Little History 145 Getting Started 146 Variables and Data Types 149 Operators 152 Arrays and Pointers 156 Conditional Branching 163 Loops 168 Functions and Blocks 175 Characters and Strings 179 Input/Output 184 Data Structures 193 Memory Management 196 The Preprocessor 200 Organizing Programs 206 Summary 227 CHAPTER 7: THE OBJECTIVE-C LANGUAGE 229 Object-Oriented Programming 230 Classes and Objects 231 Methods 234 Data Hiding 240 Subclassing 242 Messaging 246 Protocols and Informal Protocols 247 Naming Conventions 252 Creating and Destroying Objects 253 Memory Management 257 Accessor Methods and Properties 261 Summary 288 CHAPTER 8: INTRODUCTION TO COCOA 291 Connecting Cocoa Interfaces 292 Connecting Interfaces Manually with Outlets and Actions 292 Working with Cocoa Bindings 302 The Model/View/Controller Design Pattern 309 Summary 310 xi ffttoocc..iinndddd xxii 1122//1155//0099 33::2233::3344 PPMM CONTENTS CHAPTER 9: DOCUMENT-BASED COCOA APPLICATIONS 313 Working with Documents 314 Creating a New Document 315 Subclassing Controls in Interface Builder 327 Connecting Menus 330 Summary 337 CHAPTER 10: CORE DATA–BASED COCOA APPLICATIONS 341 Archiving Objective-C Objects 342 Modeling Objects with Core Data 343 Connecting User Interface to Core Data 348 Selecting Files with Open Panels 362 Creating New Documents 366 Sorting Results 370 Using Transient Objects 372 Application Preferences 376 Summary 384 PART III: SCRIPT PROGRAMMING CHAPTER 11: OVERVIEW OF SCRIPTING LANGUAGES 389 What Is a Script? 390 What Is a Scripting Language? 390 Bash 391 Why Bash? 391 More Information 395 AppleScript 396 Why AppleScript? 396 More Information 400 Python 400 Why Python? 401 More Information 410 Ruby 410 Why Ruby? 411 More Information 417 JavaScript 417 Why JavaScript? 417 More Information 421 Other Scripting Languages 421 Summary 422 xii ffttoocc..iinndddd xxiiii 1122//1155//0099 33::2233::3344 PPMM CONTENTS CHAPTER 12: THE BASH SHELL 425 Getting Started 425 The Command-Line Interface 426 Interactive versus Script 426 The Terminal Application 427 Editors 427 Confi guring Bash 429 Unix Basics 433 Paths 433 Locating and Learning Commands 434 Running Commands and Other Executables 436 Redirecting Input and Output 438 Navigating the File System 443 Working with Files and Directories 446 File Permissions 449 Globbing 452 Searching for Files 455 Working with Text 458 Process Control 463 Mac OS X Exclusive Commands 466 Overview of Other Commands 467 Shell Programming 468 Scripts 468 Variables 469 Quoting 473 Conditional Branching 474 Looping 478 Functions 480 Summary 484 CHAPTER 13: APPLESCRIPT AND APPLESCRIPTOBJC 487 AppleScript 488 Creating an AppleScript 488 Scriptable and Recordable Applications 490 Apple Events 490 Variables and Data Types 491 Handlers 497 Control Statements 501 Operators 511 Specifying Elements 515 Scripts and Objects 518 xiii ffttoocc..iinndddd xxiiiiii 1122//1155//0099 33::2233::3355 PPMM CONTENTS Classes 521 Working with Scripts 521 AppleScript Applications 531 The AppleScriptObjC Bridge 532 Using Xcode 533 Using Interface Builder 535 Summary 549 CHAPTER 14: JAVASCRIPT, DASHBOARD, AND DASHCODE 553 JavaScript 554 Dashboard 560 Dashcode 576 Summary 589 Appendix A: Answers to Exercises 591 Appendix B: Developer Resources 631 INDEX 633 xiv ffttoocc..iinndddd xxiivv 1122//1155//0099 33::2233::3355 PPMM PART I Mac OS X Developer Resources (cid:1) CHAPTER 1: The Mac OS X Environment (cid:1) CHAPTER 2: Developer Tools (cid:1) CHAPTER 3: Xcode (cid:1) CHAPTER 4: Interface Builder cc0011..iinndddd 11 1122//1122//0099 11::0011::1155 PPMM 1 The Mac OS X Environment WHAT YOU WILL LEARN IN THIS CHAPTER: ➤ How the Mac OS X operating system is structured, including what the major areas of the system are and how they work together ➤ How to use Mac OS X ’ s command - line interface ➤ How applications take advantage of the operating system services on Mac OS X ➤ How Apple encourages a common look and feel for Mac OS X applications Welcome to the wonderful world of Mac OS X, the next - generation operating system from Apple Computer! The Mac OS X operating system powers modern Macintosh computers. After many long years and a few scrapped attempts to modernize the older Mac OS operating system, Apple released Mac OS X in April 2001. Since then, Apple has released a steady stream of upgrades and system updates. This book was written around Mac OS X v10.6 Snow Leopard, the latest version. To write software for Mac OS X, you need to know your way around the system. By now you may already be familiar with Mac OS X ’ s applications and user interface style. Those things all rest on top of a number of subsystems and services that make up the Mac OS X operating system. cc0011..iinndddd 33 1122//1122//0099 11::0011::2244 PPMM

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.