Table Of ContentXcode 6
Start to Finish
Developer’s Library Series
Visit developers-library.com for a complete list of available products
The Developer’s Library Series from Addison-Wesley provides
practicing programmers with unique, high-quality references and
tutorials on the latest programming languages and technologies they
use in their daily work. All books in the Developer’s Library are written by
expert technology practitioners who are exceptionally skilled at organizing
and presenting information in a way that’s useful for other programmers.
Developer’s Library books cover a wide range of topics, from open-
source programming languages and databases, Linux programming,
Microsoft, and Java, to Web development, social networking platforms,
Mac/iPhone programming, and Android programming.
Xcode 6
Start to Finish
iOS and OS X
Development
Fritz Anderson
NewYork• Boston• Indianapolis• SanFrancisco
Toronto• Montreal• London• Munich• Paris• Madrid
Capetown• Sydney• Tokyo• Singapore• MexicoCity
Editor-in-Chief
MarkL.Taub
Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheir
productsareclaimedastrademarks.Wherethosedesignationsappearinthisbook, SeniorAcquisitionsEditor
andthepublisherwasawareofatrademarkclaim,thedesignationshavebeenprinted TrinaMacDonald
withinitialcapitallettersorinallcapitals.
SeniorDevelopmentEditor
XcodeisatrademarkofApple,Inc.,registeredintheU.S.andothercountries. ChrisZahn
Theauthorandpublisherhavetakencareinthepreparationofthisbook,butmake ManagingEditor
noexpressedorimpliedwarrantyofanykindandassumenoresponsibilityforerrors JohnFuller
oromissions.Noliabilityisassumedforincidentalorconsequentialdamagesin
connectionwithorarisingoutoftheuseoftheinformationorprogramscontained Full-ServiceProduction
herein. Manager
JulieB.Nahil
Forinformationaboutbuyingthistitleinbulkquantities,orforspecialsales
opportunities(whichmayincludeelectronicversions;customcoverdesigns;and CopyEditor
contentparticulartoyourbusiness,traininggoals,marketingfocus,orbranding StephanieGeels
interests),pleasecontactourcorporatesalesdepartmentatcorpsales@pearsoned.com
or(800)382-3419. Indexer
TedLaux
Forgovernmentsalesinquiries,[email protected].
Proofreader
ForquestionsaboutsalesoutsidetheUnitedStates,pleasecontact
KathleenAllain
[email protected].
VisitusontheWeb:informit.com/aw TechnicalReviewers
DuncanChampney
LibraryofCongressCataloging-in-PublicationData ChuckRoss
Anderson,Fritz. DanWood
Xcode6starttofinish:iOSandOSXdevelopment/FritzAnderson.
pages cm EditorialAssistant
Includesindex. OliviaBasegio
ISBN978-0-13-405277-9(pbk.:alk.paper)
CoverDesigner
1.MacOS.2.iOS(Electronicresource)3.Macintosh(Computer)—Programming.
ChutiPrasertsith
4.iPhone(Smartphone)—Programming.5.Applicationsoftware—Development.
I.Title. Compositor
QA76.774.M33A5342015 LoriHughes
005.4’46—dc23
2015004190
Copyright©2015PearsonEducation,Inc.
Allrightsreserved.PrintedintheUnitedStatesofAmerica.Thispublicationis
protectedbycopyright,andpermissionmustbeobtainedfromthepublisherpriorto
anyprohibitedreproduction,storageinaretrievalsystem,ortransmissioninany
formorbyanymeans,electronic,mechanical,photocopying,recording,orlikewise.
Toobtainpermissiontousematerialfromthiswork,pleasesubmitawrittenrequest
toPearsonEducation,Inc.,PermissionsDepartment,200OldTappanRoad,Old
Tappan,NewJersey07675,oryoumayfaxyourrequestto(201)236-3290.
ISBN-13:978-0-13-405277-9
ISBN-10:0-13-405277-3
TextprintedintheUnitedStatesonrecycledpaperatEdwardsBrothersMalloyin
AnnArbor,Michigan.
Firstprinting,June2015
(cid:118)
For the Honorable Betty Shelton Cole,
a tough old broad
(cid:118)
This page intentionally left blank
Contents at a Glance
Contents ix
Acknowledgments xxiii
AbouttheAuthor xxv
Introduction 1
I First Steps 7
1 GettingXcode 9
2 KickingtheTires 17
3 SimpleWorkflowandPassiveDebugging 25
4 ActiveDebugging 35
5 Compilation 45
6 AddingaLibraryTarget 69
7 VersionControl 79
II The Life Cycle of an iOS Application 105
8 StartinganiOSApplication 107
9 AniOSApplication:Model 117
10 AniOSApplication:Controller 141
11 BuildingaNewView 157
12 AutoLayoutinaNewView 185
13 AddingTableCells 207
14 AddinganEditor 227
15 UnitTesting 243
16 MeasurementandAnalysis 265
viii ContentsataGlance
17 AniOSExtension 279
18 Provisioning 297
III Xcode for Mac OS X 319
19 StartinganOSXApplication 321
20 Bindings:WiringanOSXApplication 343
21 Localization 373
22 BundlesandPackages 401
23 PropertyLists 417
IV Xcode Tasks 433
24 DocumentationinXcode 435
25 TheXcodeBuildSystem 459
26 Instruments 489
27 Debugging 515
28 Snippets 531
V Appendixes 547
A SomeBuildVariables 549
B Resources 565
Index 579
Contents
Acknowledgments xxiii
AbouttheAuthor xxv
Introduction 1
HowThisBookIsOrganized 1
AboutVersions 4
AbouttheCode 4
Conventions 5
I First Steps 7
1 GettingXcode 9
BeforeYouBegin 9
InstallingXcode 10
Command-LineTools 11
RemovingXcode 11
AppleDeveloperPrograms 12
DownloadingXcode 13
AdditionalDownloads 14
Summary 15
2 KickingtheTires 17
StartingXcode 17
HelloWorld 19
ANewProject 19
QuietingXcodeDown 22
BuildingandRunning 22
TheRealThing 24
GettingRidofIt 24
Summary 24
3 SimpleWorkflowandPassiveDebugging 25
CreatingtheProject 25
Building 29
Running 30