iPhone Development Guide
Development Environments: Xcode
2009-01-06
Apple Inc.
© 2009 Apple Inc.
All rights reserved.
No part of this publication may be reproduced,
stored in a retrieval system, or transmitted, in
any form or by any means, mechanical,
electronic, photocopying, recording, or
otherwise, without prior written permission of
Apple Inc., with the following exceptions: Any
person is hereby authorized to store
documentation on a single computer for
personal use only and to print copies of
documentation for personal use provided that
the documentation contains Apple’s copyright
notice.
The Apple logo is a trademark of Apple Inc.
Use of the “keyboard” Apple logo
(Option-Shift-K) for commercial purposes
without the prior written consent of Apple may
constitute trademark infringement and unfair
competition in violation of federal and state
laws.
No licenses, express or implied, are granted
with respect to any of the technology described
in this document. Apple retains all intellectual
property rights associated with the technology
described in this document. This document is
intended to assist application developers to
develop applications only for Apple-labeled
computers.
Every effort has been made to ensure that the
information in this document is accurate. Apple
is not responsible for typographical errors.
Apple Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
Apple, the Apple logo, Cocoa, iPhoto, iPod,
iTunes, Keychain, Mac, Mac OS, Objective-C,
and Xcode are trademarks of Apple Inc.,
registered in the United States and other
countries.
Finder, iPhone, and Spotlight are trademarks
of Apple Inc.
OpenGL is a registered trademark of Silicon
Graphics, Inc.
Simultaneously published in the United States
and Canada.
Even though Apple has reviewed this document,
APPLE MAKES NO WARRANTY OR REPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH RESPECT TO
THIS DOCUMENT, ITS QUALITY, ACCURACY,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR
PURPOSE. AS A RESULT, THIS DOCUMENT IS
PROVIDED “AS IS,” AND YOU, THE READER, ARE
ASSUMING THE ENTIRE RISK AS TO ITS QUALITY
AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES RESULTING FROM ANY
DEFECT OR INACCURACY IN THIS DOCUMENT, even
if advised of the possibility of such damages.
THE WARRANTY AND REMEDIES SET FORTH ABOVE
ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL
OR WRITTEN, EXPRESS OR IMPLIED. No Apple
dealer, agent, or employee is authorized to make
any modification, extension, or addition to this
warranty.
Some states do not allow the exclusion or limitation
of implied warranties or liability for incidental or
consequential damages, so the above limitation or
exclusion may not apply to you. This warranty gives
you specific legal rights, and you may also have
other rights which vary from state to state.
Contents
Introduction
Introduction 9
Organization of This Document 9
See Also 10
Chapter 1
The Development Process 11
Essential Development Tasks 11
Creating an iPhone Project 12
Editing Code 13
Using Code Completion 14
Accessing Documentation 15
Building and Running Your Application 17
Measuring Application Performance 18
Further Exploration 18
Chapter 2
Tutorial: Hello, World! 19
Create the Project 19
Write the Code 21
Run the Application 23
Further Exploration 23
Chapter 3
Running Applications 25
Setting Your Application’s Target iPhone OS Release 25
Setting the Active SDK 26
Setting the Active Build Configuration 27
Building Your Application 28
Running Your Application 28
Streamlining the Build-and-Run Workflow 29
Managing Application Data 29
Further Exploration 29
Chapter 4
Using iPhone Simulator 31
Manipulating the Hardware 31
Performing Gestures 32
Installing Applications 32
Uninstalling Applications 32
Resetting Content and Settings 33
Core Location Functionality 33
3
2009-01-06 | © 2009 Apple Inc. All Rights Reserved.
iPhone Simulator File System on Host 33
Further Exploration 33
Chapter 5
Managing Devices 35
Preparing Devices for Development 35
Setting Your Application ID 37
Registering Your Device with the Program Portal 37
Installing iPhone OS on Your Device 38
Obtaining Your Development Certificate 38
Adding Your Development Certificate to Your Keychain 39
Obtaining Your Provisioning Profile 40
Adding Your Provisioning Profile to the Xcode Organizer 40
Installing Your Provisioning Profile on Your Device 40
Restoring System Software 40
Running Applications on a Device 41
Viewing Console and Crash Logs 42
Capturing Screen Shots 43
Managing Your Digital Identifications 43
Chapter 6
Debugging Applications 45
General Debugging Tasks 45
Memory Leaks 46
Chapter 7
Tuning Applications 49
The Instruments Application 49
The Shark Application 50
Chapter 8
Publishing Applications for Testing 51
Adding Testers to Your Team 52
Adding the iTunes Artwork to Your Application 52
Distributing Your Application to Testers 53
Adding Symbol Information to Crash Logs from Testers 54
Chapter 9
Conditional Compilation and Linkage 55
Compiling Source Code Conditionally for iPhone Applications 55
Linking Frameworks Conditionally for iPhone Applications 56
4
2009-01-06 | © 2009 Apple Inc. All Rights Reserved.
CONTENTS
Chapter 10
iPhone Development FAQ 59
Appendix A
Instructions for Application Testers 61
Sending Your Device ID to Developers 61
Installing an Application for Testing 61
Sending Crash Reports to Developers 62
Sending Crash Reports from Macs 62
Sending Crash Reports from Windows 62
Glossary 65
Document Revision History 67
5
2009-01-06 | © 2009 Apple Inc. All Rights Reserved.
CONTENTS