Sams Teach Yourself Xcode® 4 in 24 Hours
Total Page:16
File Type:pdf, Size:1020Kb
John Ray William Ray SamsTeachYourself Xcode® 4 in Hours24 800 East 96th Street, Indianapolis, Indiana, 46240 USA Sams Teach Yourself Xcode®4 in 24 Hours Editor-in-Chief Copyright © 2012 by Pearson Education, Inc. Greg Wiegand 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 Acquisitions Editor written permission from the publisher. No patent liability is assumed with respect to the use of Laura Norman the information contained herein. Although every precaution has been taken in the preparation of Development this book, the publisher and author assume no responsibility for errors or omissions. Nor is any Editor liability assumed for damages resulting from the use of the information contained herein. Keith Cline ISBN-13: 978-0-672-33587-7 ISBN-10: 0-672-33587-5 Managing Editor The Library of Congress Cataloging-in-Publication data is on file. Kristy Hart Printed in the United States of America Project Editor First Printing June 2012 Andy Beaster Trademarks Copy Editor 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 Keith Cline of a term in this book should not be regarded as affecting the validity of any trademark or service Indexer mark. Tim Wright Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no Proofreader warranty or fitness is implied. The information provided is on an “as is” basis. The author and the Chrissy White 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. Technical Editor Bulk Sales Greg Kettell Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk pur- Publishing chases or special sales. For more information, please contact Coordinator U.S. Corporate and Government Sales Cindy Teeters 1-800-382-3419 [email protected] Book Designer For sales outside of the U.S., please contact Gary Adair International Sales Compositor [email protected] Nonie Ratcliff Contents at a Glance Introduction............................................................................... 1 HOUR 1 Xcode 4..................................................................................... 3 2 Just Enough Objective-C and Cocoa ............................................. 23 3 Understanding the MVC Design Pattern........................................ 57 4 Using Xcode Templates to Create Projects ...................................... 71 5 Managing Projects and Resources ................................................ 95 6 Using the Xcode Code Source Editor............................................ 117 7 Working with the Xcode 4 Documentation .................................. 145 8 Creating User Interfaces ........................................................... 165 9 Connecting a GUI to Code ........................................................ 195 10 Creating iOS Application Workflows with Storyboarding................ 215 11 Building and Executing Applications .......................................... 251 12 Using Source Control................................................................ 279 13 Xcode-Supported Languages...................................................... 311 14 Planning for Re-use: Frameworks and Libraries ............................ 329 15 Putting It All Together: Building an OS X Application ................... 355 16 Building an iOS Application ..................................................... 399 17 Attaching Big Data: Using Core Data in Your Applications ............ 435 18 Test Early, Test Often ................................................................ 465 19 Getting the Bugs Out ............................................................... 487 20 Keeping things Organized: Shared Workspaces ............................. 509 21 Advanced: Analyzing Code with Instruments ............................... 533 22 Managing and Provisioning iOS Devices ..................................... 549 23 Distributing Your Applications................................................... 567 24 Xcode CLI Utilities ................................................................... 587 Index .................................................................................... 603 Table of Contents Introduction 1 HOUR 1: Xcode 4 ....................................................................................... 3 Welcome to Xcode ................................................................................ 3 The Apple Developer Programs .............................................................. 8 Installing the Xcode Developer Tools ...................................................... 11 The Nickel Tour .................................................................................. 13 Preparing Your iOS Device (Optional) .................................................... 17 Summary .......................................................................................... 20 Q&A ................................................................................................ 20 Workshop .......................................................................................... 21 HOUR 2: Just Enough Objective-C and Cocoa 23 Object-Oriented Programming and Objective-C ...................................... 23 What Is Objective-C? .......................................................................... 25 Objective-C Programming Basics .......................................................... 38 Memory Management and Automatic Reference Counting........................ 48 What Is Cocoa? .................................................................................. 50 Cocoa Versus Cocoa Touch .................................................................. 51 Summary .......................................................................................... 54 Q&A ................................................................................................ 55 Workshop .......................................................................................... 55 HOUR 3: Understanding the MVC Design Pattern 57 Development, Design Patterns, and MVC .............................................. 57 How Xcode Implements MVC .............................................................. 60 An MVC Walkthrough ........................................................................ 64 Summary .......................................................................................... 68 Q&A ................................................................................................ 68 Workshop .......................................................................................... 69 v Table of Contents HOUR 4: Using Xcode Templates to Create Projects 71 Available Project Types ........................................................................ 71 The Project-Creation Process ................................................................ 83 You’ve Got a Project ............................................................................ 88 Summary .......................................................................................... 91 Q&A ................................................................................................ 91 Workshop .......................................................................................... 92 HOUR 5: Managing Projects and Resources 95 Getting Your Bearings.......................................................................... 95 Managing Project Files ........................................................................ 99 Managing Frameworks and Libraries .................................................. 108 Managing Groups ............................................................................ 110 Managing Target Properties ................................................................ 111 Summary ........................................................................................ 114 Q&A .............................................................................................. 115 Workshop ........................................................................................ 115 HOUR 6: Using the Xcode Source Editor 117 Understanding Editor Basics................................................................ 117 Navigating Within and Between Files .................................................. 126 Using the Assistant Editor .................................................................. 131 Correcting Errors and Warnings in the Issue Navigator .......................... 133 Refactoring Code .............................................................................. 135 Using Code Snippets .......................................................................... 138 Summary ........................................................................................ 142 Q&A .............................................................................................. 142 Workshop ........................................................................................ 142 HOUR 7: Working with the Xcode 4 Documentation 145 Overview of Documentation Resources ...............................................