iPhoneDevelopmentGuideDevelopmentEnvironments:Xcode2009-03-04AppleInc.©2009AppleInc.Allrightsreserved.Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmitted,inanyformorbyanymeans,mechanical,electronic,photocopying,recording,orotherwise,withoutpriorwrittenpermissionofAppleInc.,withthefollowingexceptions:AnypersonisherebyauthorizedtostoredocumentationonasinglecomputerforpersonaluseonlyandtoprintcopiesofdocumentationforpersonaluseprovidedthatthedocumentationcontainsApple’scopyrightnotice.TheApplelogoisatrademarkofAppleInc.Useofthe“keyboard”Applelogo(Option-Shift-K)forcommercialpurposeswithoutthepriorwrittenconsentofApplemayconstitutetrademarkinfringementandunfaircompetitioninviolationoffederalandstatelaws.Nolicenses,expressorimplied,aregrantedwithrespecttoanyofthetechnologydescribedinthisdocument.Appleretainsallintellectualpropertyrightsassociatedwiththetechnologydescribedinthisdocument.ThisdocumentisintendedtoassistapplicationdeveloperstodevelopapplicationsonlyforApple-labeledcomputers.Everyefforthasbeenmadetoensurethattheinformationinthisdocumentisaccurate.Appleisnotresponsiblefortypographicalerrors.AppleInc.1InfiniteLoopCupertino,CA95014408-996-1010AppStoreisaservicemarkofAppleInc.Apple,theApplelogo,Cocoa,iPhoto,iPod,iTunes,Keychain,Mac,MacOS,Objective-C,andXcodearetrademarksofAppleInc.,registeredintheUnitedStatesandothercountries.Finder,Instruments,iPhone,andSpotlightaretrademarksofAppleInc.IntelandIntelCoreareregisteredtrademarksofIntelCorportationoritssubsidiariesintheUnitedStatesandothercountries.OpenGLisaregisteredtrademarkofSiliconGraphics,Inc.SimultaneouslypublishedintheUnitedStatesandCanada.EventhoughApplehasreviewedthisdocument,APPLEMAKESNOWARRANTYORREPRESENTATION,EITHEREXPRESSORIMPLIED,WITHRESPECTTOTHISDOCUMENT,ITSQUALITY,ACCURACY,MERCHANTABILITY,ORFITNESSFORAPARTICULARPURPOSE.ASARESULT,THISDOCUMENTISPROVIDED“ASIS,”ANDYOU,THEREADER,AREASSUMINGTHEENTIRERISKASTOITSQUALITYANDACCURACY.INNOEVENTWILLAPPLEBELIABLEFORDIRECT,INDIRECT,SPECIAL,INCIDENTAL,ORCONSEQUENTIALDAMAGESRESULTINGFROMANYDEFECTORINACCURACYINTHISDOCUMENT,evenifadvisedofthepossibilityofsuchdamages.THEWARRANTYANDREMEDIESSETFORTHABOVEAREEXCLUSIVEANDINLIEUOFALLOTHERS,ORALORWRITTEN,EXPRESSORIMPLIED.NoAppledealer,agent,oremployeeisauthorizedtomakeanymodification,extension,oradditiontothiswarranty.Somestatesdonotallowtheexclusionorlimitationofimpliedwarrantiesorliabilityforincidentalorconsequentialdamages,sotheabovelimitationorexclusionmaynotapplytoyou.Thiswarrantygivesyouspecificlegalrights,andyoumayalsohaveotherrightswhichvaryfromstatetostate.ContentsIntroductionIntroduction9OrganizationofThisDocument9SeeAlso10Chapter1TheDevelopmentProcess11EssentialDevelopmentTasks11CreatinganiPhoneProject12EditingCode13UsingCodeCompletion14AccessingDocumentation15BuildingandRunningYourApplication17MeasuringApplicationPerformance18FurtherExploration18Chapter2Tutorial:Hello,World!19CreatetheProject19WritetheCode21RuntheApplication23FurtherExploration23Chapter3RunningApplications25RunningSampleApplications25SettingYourApplication’sTargetiPhoneOSRelease26SettingtheActiveSDK27SettingtheActiveBuildConfiguration28BuildingYourApplication29RunningYourApplication30StreamliningtheBuild-and-RunWorkflow30ManagingApplicationData30FurtherExploration32Chapter4UsingiPhoneSimulator33ManipulatingtheHardware33PerformingGestures34InstallingApplications34UninstallingApplications34ResettingContentandSettings3532009-03-04|©2009AppleInc.AllRightsReserved.CoreLocationFunctionality35AccelerometerAccess35iPhoneSimulatorFileSystemonHost35FurtherExploration36Chapter5ManagingDevices37AccessingtheiPhoneDeveloperProgramPortal37PreparingDevicesforDevelopment37SettingYourApplicationID39RegisteringYourDevicewiththeProgramPortal39InstallingiPhoneOSonYourDevice40ObtainingYourDevelopmentCertificate41AddingYourDevelopmentCertificatetoYourKeychain41ObtainingYourProvisioningProfile42AddingYourProvisioningProfiletotheXcodeOrganizer42InstallingYourProvisioningProfileonYourDevice42RestoringSystemSoftware43RunningApplicationsonaDevice43ViewingConsoleandCrashLogs44CapturingScreenShots45ManagingYourDigitalIdentities45Chapter6DebuggingApplications47GeneralDebuggingTasks47MemoryLeaks48Chapter7TuningApplications51TheInstrumentsApplication51TheSharkApplication52Chapter8PublishingApplicationsforTesting53AddingTesterstoYourTeam54AddingtheiTunesArtworktoYourApplication54DistributingYourApplicationtoTesters55AddingSymbolInformationtoCrashLogsfromTesters56Chapter9ConditionalCompilationandLinkage57CompilingSourceCodeConditionallyforiPhoneApplications57LinkingFrameworksConditionallyforiPhoneApplications5842009-03-04|©2009AppleInc.AllRightsReserved.CONTENTSChapter10iPhoneDevelopmentFAQ61AppendixAInstructionsforApplicationTesters63SendingYourDeviceIDtoDevelopers63InstallinganApplicationforTesting63SendingCrashReportstoDevelopers64SendingCrashReportsfromMacs64SendingCrashReportsfromWindows64Glossary67DocumentRevisionHistory6952009-03-04|©2009AppleInc.AllRightsReserved.CONTENTS62009-03-04|©2009App