Objective-C
Jiva DeVoe
Objective-C
Published by
Wiley Publishing, Inc.
111 River St.
Hoboken, NJ 07030-5774
www.wiley.com
Copyright 2011 by Wiley Publishing, Inc., Indianapolis, Indiana
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-47922-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 specifically disclaim all warranties, including without limitation warranties of fitness 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 Website 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 Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites 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 or to obtain technical support, please contact our Customer Care Department within the U.S. at (877) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Library of Congress Control Number: 2010943062
Trademarks: Wiley, the Wiley logo, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc., in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Objective-C is a registered trademark of Apple, Inc. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
Dedication
For my wife, Dawn, and my children, Robert, Alex, and Izzy. You are, and always will be, the most important people in the world to me.
About the Author
Jiva DeVoe has been writing software for nearly 25 years, starting with his Commodore VIC-20 using BASIC and assembly language, and gradually working his way through C, C++, Python, Ruby, Java and finally Objective-C. In 2001, he founded Random Ideas, LLC, a software company dedicated to building great applications for the Mac. When the iPhone SDK was announced, he was honored to be selected as one of the earliest developers to have access to the SDK, and using it, he developed several applications that were available in the iTunes App Store when it launched on July 11, 2008. Since that time, his iPhone applications have received several awards, including being chosen as among the Top 100 apps and games in the App Store, and been featured as Apple Staff Picks and in Apple Advertisements. Today, Jiva continues to work full time for his company, Random Ideas, developing great iPhone and Mac applications. He lives with his wife, three children, and two basset hounds in the dusty desert of Arizona.
Credits
Acquisitions Editor
Aaron Black
Executive Editor
Jody Lefevere
Project Editor
Beth Taylor
Technical Editor
Brad Miller
Copy Editor
Beth Taylor
Editorial Director
Robyn Siesky
Editorial Manager
Rosemarie Graham
Business Manager
Amy Knies
Senior Marketing Manager
Sandy Smith
Vice President and Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Barry Pruett
Project Coordinator
Katherine Crocker
Production Specialist
Carrie A. Cesavice
Quality Control Technician
Melissa Cossell
Proofreading and Indexing
Laura Bowman, Evelyn Wellborn, BIM Indexing & Proofreading Services
Preface
Objective-C gets a raw deal in the IT industry. Though it's a powerful and dynamic object oriented language, it doesn't get nearly the amount of recognition that C++, Java, and others get.
When I wrote Cocoa Touch for iPhone OS 3, I knew that it needed a companion book, one which helped people over the hump of learning Objective-C before moving on to the higher level frameworks, Cocoa, and Cocoa Touch.
So when the opportunity came to write a book dedicated to Objective-C, the language, I jumped at it!
In the end, I feel I have been given an opportunity to contribute to the foundation of new Mac, iPhone and iPad developers knowledge through this book, and I'm tremendously excited by that. I love the idea that this book might be a catalyst to helping Objective-C grow, not just on these, but across many different platforms. There's no reason that Objective-C shouldn't be used more on platforms such as Unix, Windows, and so on.
As a reader, you are expected to have only a limited knowledge of computers. I have tried to approach the subject from the absolute bare essentials, but you will need at least a basic background in how to navigate around a computer.
If you already know some programming languages, that won't hurt you here. Some of what I discuss will be review for you, but don't worry, there's plenty of specifics for Objective-C that you will pick up.
If you already have a background in Objective-C, I hope that you will find some nuggets of information you didn't know in this book. I've tried to keep it in an accessible form so that you can look up specifics that you're looking for. You may not read it cover to cover, but it should give you the ability to jump to specific parts and gain insight into how to do what you are looking to do.
With regard to conventions used within this book, I've tried to be reasonably consistent, and also tried to generally err on the side of Apple conventions when prudent. The only notable exception has been in my use of the phrase method to indicate functions on instances and classes. Apple generally prefers the term message. This is in part due to the influence of Smalltalk on Objective-C.
When referring to keyboard shortcuts, I opted to use the term Command-Key to indicate keyboard shortcuts using the key directly to the left of the space key on most Apple keyboards. You may also know this as the Apple key, since prior to only a few years ago, it included a small Apple logo on it. Additionally, the key next to the Command-Key, has been called the Option-Key and the key next to that, the Control-Key. These should all be consistent with Apple documentation conventions.