Everything You Need to Know to Become an Objective-C Guru Learn Objective-C Mark Dalrymple | Scott Knaster spine = 0.8382" 360 page count COMPANION eBOOK SEE LAST PAGE FOR DETAILS ON
Trang 1Everything You Need to Know
to Become an Objective-C Guru
Learn Objective-C
Mark Dalrymple | Scott Knaster
spine = 0.8382" 360 page count
COMPANION eBOOK SEE LAST PAGE FOR DETAILS ON $10 eBOOK VERSION
US $39.99
Shelve in Mac OS X Development
User level:
Beginner–Intermediate
www.apress.com
SOURCE CODE ONLINE
BOOKS FOR PROFESSIONALS BY PROFESSIONALS®
ISBN 978-1-4302-1815-9
9 781430 218159
5 3 9 9 9
• Learn the native programming language for Mac OS X,
as well as the iPhone!
• Get up and running quickly with Objective-C We don’t waste time teaching you basic programming; instead, we focus on what
makes Objective-C different and cool.
• Learn about sophisticated programming concepts, including object-oriented programming, the Open-Closed Principle,
refactoring, key-value coding, and predicates.
In this book, you’ll find a full exploration of the Objective-C programming
language, the primary language for creating Mac OS X and iPhone applica-tions There are goodies here for everyone, whether you’re just starting out as
a Mac developer or a grizzled programmer coming from another language
You’ll discover all of the object-oriented purity and Smalltalk heritage coolness
of Objective-C—such as instantiation, protocols for multiple inheritance, dynamic typing, and message forwarding Along the way, you’ll meet Xcode, the Mac
development environment, and you’ll learn about Apple’s Cocoa toolkit
Nearly everyone wants to be able to develop for Mac OS X or the iPhone these days, and it’s no wonder The Mac is a fun and powerful platform, and Objective-C
is a wonderful language for writing code You can have a great time programming the Mac in Objective-C We do, and want you to join us!
Mark Dalrymple is a longtime Mac and Unix programmer who has code running all over the world.
Scott Knaster is a legendary Mac programmer and author of more than
a baker’s dozen books.
this print for content only—size & color not accurate
CYAN
MAGENTA YELLOW BLACK
PANTONE 123 C
SPOT MATTE
Companion
eBook
Available
More advanced Mac and iPhone development
Trang 3Learn Objective-C
on the Mac
Penciled by MARK DALRYMPLE
Inked by SCOTT KNASTER
Trang 4Learn Objective-C on the Mac
Copyright © 2009 by Mark Dalrymple and Scott Knaster
All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic
or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher
ISBN-13 (pbk): 978-1-4302-1815-9
ISBN-13 (electronic): 978-1-4302-1816-6
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with
no intention of infringement of the trademark
Java™ and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the US and other countries Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was written without endorsement from Sun Microsystems, Inc
Lead Editors: Clay Andres and Dave Mark
Technical Reviewer: Jeff LaMarche
Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Project Manager: Denise Santoro Lincoln
Copy Editor: Heather Lang
Associate Production Director: Kari Brooks-Copony
Production Editor: Laura Esterman
Compositor/Artist/Interior Designer: Diana Van Winkle
Proofreader: Greg Teague
Indexer: Toma Mulligan
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013 Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com,
or visit http://www.springeronline.com
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley,
CA 94705 Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use
eBook versions and licenses are also available for most titles For more information, reference our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales
The information in this book is distributed on an “as is” basis, without warranty Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work
The source code for this book is available to readers at http://www.apress.com
Trang 5For Jerri Shertzer—teacher, mentor, friend
—Mark
Trang 6INDEX 337
code folding, 117
Code Sense (code completion), 106
collapsing/expanding a section of code, 116
command-line parameters, 29
Command Line Utility, 6
comments, fixing manually, 112
completion menu as a quick API class reference,
107
Console window, 7
continue button, 126
converting NSEnumerator loops into fast
enumeration, 148
.cpp file extension, 8
creating the Hello Objective-C program, 5
datatips, 128
debugger controls, 126
debugging, 123
delimiters, closing up, 108
documentation and reference materials for, 121
documentation bookmarks, 123
Edit all in Scope mode, 110
Editor icon, 104
emacs, list of key bindings, 113
features for writing code easier, 105
Find in Project command, 109
focus ribbon, 116
Foundation Tool, 6
function menu, 118
GDB debugger, 124
GNU Compiler Collection (GCC), 8
Groups & Files pane, 90, 103–104
Groups, setting up, 90
gutter, 116, 124
highlighting a section of code, 116
included files menu, 120
indenting source code, 105
Key Bindings pane, 105
keyboard shortcuts, table of, 129
kissing the parentheses, 108
launch arguments, 29
lock icon, 120
making a file read-only, 120
making a new Cocoa Application project, 250
.m file extension, 8
navigating around source code, 113
navigating up and down a class hierarchy, 119
navigation bar, 118
New Project, 6 objc_exception_throw, 144 opening a source file in its own window, 104 organizing the project and source code editors, 103
organizing the source files in an Xcode project, 90
#pragma mark, 119 program state, definition of, 128 projectwide search and replace, 109 project window, 6, 90
property list editor, 268 quickly opening a header file, 115 recovering from a previous snapshot, 109 refactoring tools, 111
Re-indent selection, 105 Research Assistant window, 121 running a program with the debugger, 124 search box, using, 104, 114
searching Apple’s official API documentation, 122 selecting Breakpoints from the Run menu, 143 selecting File, New File, 88, 91
selecting Objective-C class, 88, 91 single-stepping through code, 126 Snapshot checkbox, 112
Snapshot Failed error message, 109 splitting the source window in half, 120 standard boilerplate code in newly created files, 90
step out button, 128 step over button, 126 supplying a file path in, 29 syntax coloring, 111 taking a snapshot of the project state, 109 Targets, 104
Treat Warnings as Errors checkbox, 12 using a Debug build configuration, 124 using Objective-C++, 312
using the program defaults, 101 working with Xcode 3.1, 101 See also Cocoa
.xib files, definition of, 253
Z
zone, definition of, 238
Trang 7Offer valid through 6/09.