Mastering Xcode
Develop and Design
Second Edition
Maurice Kelly and Joshua Nozzi
Mastering Xcode: Develop and Design, Second Edition
Maurice Kelly and Joshua Nozzi
Peachpit Press
www.peachpit.com
To report errors, please send a note to
Peachpit Press is a division of Pearson Education.
Copyright 2014 by Joshua Nozzi
Editor: Robyn G. Thomas
Production editor: David Van Ness
Copyeditor: Scout Festa
Technical editor: Mark Goody
Compositor: David Van Ness
Indexer: Valerie Haynes Perry
Cover design: Aren Straiger
Interior design: Mimi Heft
Notice of Rights
All rights reserved. No part of this book may be reproduced or transmitted in any form by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. For information on getting permission for reprints and excerpts, contact .
Notice of Liability
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of the book, neither the authors nor Peachpit 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 instructions contained in this book or by the computer software and hardware products described in it.
Trademarks
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 Peachpit was aware of a trademark claim, the designations appear as requested by the owner of the trademark. All other product names and services identified throughout this book are used in editorial fashion only and for the benefit of such companies with no intention of infringement of the trademark. No such use, or the use of any trade name, is intended to convey endorsement or other affiliation with this book.
ISBN-13: 978-0-321-86162-7
ISBN-10: 0-321-86162-0
9 8 7 6 5 4 3 2 1
Printed and bound in the United States of America
To my wife, Fiona, and our beautiful daughters, Aoibhnn and Caoimhe
I thank you for your support and patience while Ive been distracted by this book.
To my parentsthank you for buying our first family computer and
setting me on the course that led me to do what I love.
Maurice Kelly
Thanks to my peers, my friends, my family, and my partner
for their enthusiastic support. Special thanks to my coauthor:
May our Caoimhes live long, happy lives.
Joshua Nozzi
Maurice Kelly
About the Author
Maurice Kelly has been a software engineer since leaving university in 2001. After spending a decade working on carrier-grade server software in C, C++, and Java, he decided to take a career departure and switched to developing Mac and iOS software. As well as being an eager consumer of all things tech, he has a passion for consuming and creating music. He lives with his wife and children just outside Dromara, a small village in the small country of Northern Ireland.
Acknowledgments
I would like to thank Josh for giving me the opportunity to work on this project in ever-increasing capacities. The first edition of this book gave me inspiration to change my career, and it has been an honor to work with him in producing the second edition. I would also like to thank my employers, Andrew Gough and Andrew Cuthbert at GCD Technologies (www.gcdtech.com), for allowing me to take on this side-project and for introducing me to Mark Goodya newfound friend, an amazing developer, and an excellent technical editor. I would like to extend many thanks to Robyn Thomas for her encouragement and for guiding this ship through patches of both stormy water and dead calm!
While Xcode is the day-to-day tool of my trade, there were a number of tools without which this book could not have been completed:
Sublime Text 2 (www.sublimetext.com/2). Combined with Brett Terpstras MarkdownEditing package, this makes a much better writing environment than Xcodes editor!
Marked (http://markedapp.com). For previewing Markdown output, there is no better application than Marked.
ScreenFloat (www.screenfloatapp.com). Capturing and managing the quantity of screen-shots required for this book needed an app like ScreenFloat.
Joshua Nozzi
About the Author
Joshua Nozzi is a self-taught technologist who has been developing software for the Mac platform since Mac OS X 10.0 debuted. Hes been using Xcode since version 1 for publishing, increasing productivity, and building scientific research applications. Hes haunted several developer communities over the years, offering help and snark in equal measures. He loves to teach technology to others. Josh lives with his partner in Southern Virginia, where he toils in obscurity, usually in sweatpants and little else.
Acknowledgments
I wish to thank the following people, whose work I used while writing this book.
Cyril Godefroy: Cyrils masterfully broken code examples demonstrated some nice highlights of the Clang static analyzer. You can find them at http://xcodebook.com/cgodefroy.
Colin Wheeler: Colins Xcode shortcut cheat sheet has saved me loads of tedium on many projects. You can find the original, downloadable version that Colin maintains at http://xcodebook.com/cwheeler.
Introduction
This book is an intermediate-level introduction to Xcode 4, Apples integrated development environment. It assumes you have some development experience and are familiar with Objective-C and the Cocoa and Cocoa Touch APIs. It wont teach you how to write code or much at all about the frameworks needed to develop OS X and iOS applications. There are other books for that. This one is strictly focused on how to use Xcode itself, whatever your development endeavors.
Of course, since Xcode is most often used with the Cocoa and Cocoa Touch APIs and Objective-C, there are basic introductions to concepts and a few code samples sprinkled here and there to illustrate various points. In these cases, you will be pointed to the documentation that Apple provides (to save you some trouble looking it up), but remember that the focus of this book is really on getting the most out of the tools and not necessarily on what youll be building with them.
A Moving Target
When the first edition of this book was released, Xcode 4.0 had just become Xcode 4.1. It was hard for anyone to predict how rapidly Apple would iterate, but in a short space of time there have been five major versions of Xcode 4 released. Each version brings enhancements, fixes, and new toolsand headaches to the authors of this book.
So just as in the introduction to the first edition, we will once again make our excuses up front and say that this book was current when we wrote it, and may or may not be by the time you read it. We hope that, however Apple chooses to change Xcode, our guidance is still relevant for the foreseeable future and that this book will be a trusty companion for up-and-coming developers for some time to come.