Start Developing iOS Apps Today Contents Introduction 5 Setup 6 GettheTools 7 Tutorial: Basics 8 CreateaNewProject 9 GetFamiliarwithXcode 11 RuniOSSimulator 12 ReviewtheSourceCode 14 CreateaStoryboard 17 AddaScenetoYourStoryboard 19 TestYourChanges 23 BuildtheBasicInterface 23 Recap 28 Structuring an App 29 App Development Process 30 DefiningtheConcept 30 DesigningaUserInterface 31 DefiningtheInteraction 31 ImplementingtheBehavior 32 ObjectsAreBuildingBlocksforApps 32 ClassesAreBlueprintsforObjects 32 ObjectsCommunicateThroughMessages 33 ProtocolsDefineMessagingContracts 34 IncorporatingtheData 34 UsetheRightResources 34 IncorporateRealData 35 Designing a User Interface 36 TheViewHierarchy 36 BuildinganInterfaceUsingViews 37 2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 2 Contents UseStoryboardstoLayOutViews 38 UseInspectorstoConfigureViews 40 UseAutoLayouttoPositionViews 41 Defining the Interaction 42 ViewControllers 42 Actions 43 Outlets 44 Controls 44 NavigationControllers 45 UseStoryboardstoDefineNavigation 45 Tutorial: Storyboards 47 AdoptAutoLayout 48 CreatingaSecondScene 50 DisplayStaticContentinaTableView 53 AddaSeguetoNavigateForward 55 CreateCustomViewControllers 63 UnwindaSeguetoNavigateBack 66 Recap 68 Implementing an App 69 Incorporating the Data 70 DesigningYourModel 70 ImplementingYourModel 71 Using Design Patterns 72 MVC 72 Target-Action 73 Delegation 73 Working with Foundation 75 ValueObjects 75 Strings 76 Numbers 77 CollectionObjects 78 Arrays 78 Sets 82 Dictionaries 83 2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 3 Contents RepresentnilwithNSNull 84 Writing a Custom Class 86 DeclaringandImplementingaClass 87 Interface 87 Implementation 87 PropertiesStoreanObject’sData 88 MethodsDefineanObject’sBehavior 89 MethodParameters 90 ImplementingMethods 91 Tutorial: Add Data 93 CreateaDataClass 94 LoadtheData 95 DisplaytheData 98 MarkItemsasCompleted 102 AddNewItems 105 Recap 111 Next Steps 112 iOS Technologies 113 UserInterface 113 Games 114 Data 115 Media 115 Finding Information 116 UseContextualHelpArticlesforXcodeGuidance 116 UseGuidesforGeneralandConceptualOverviews 118 UseAPIReferenceforClassInformation 119 UseQuickHelpforContextualSourceCodeInformation 124 UseSampleCodetoSeeReal-WorldUsage 126 Where to Go from Here 128 TakingtheToDoListApptotheNextLevel 129 Document Revision History 130 2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 4 Introduction ● “Setup” (page 6) ● “Tutorial:Basics” (page 8) 2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 5 Setup StartDevelopingiOSAppsToday providestheperfectstartingpointforiOSdevelopment.OnyourMac,you cancreateiOSappsthatrunoniPad,iPhone,andiPodtouch.Viewthisguide’sfourshortmodulesasagentle introductiontobuildingyourfirstapp—includingthetoolsyouneedandthemajorconceptsandbestpractices thatwilleaseyourpath. Thefirstthreemoduleseachendwithatutorial,whereyou’llimplementwhatyou’velearned.Attheendof thelasttutorial,you’llhavecreatedasimpleto-dolistapp. Afteryou’vebuiltyourfirstappinthisguideandareconsideringyournextendeavor,readthefourthmodule. Itexploresthetechnologiesandframeworksyoumightconsideradoptinginyournextapp.You’llbeonyour waytokeepingyourcustomersengagedandlookingforwardtothenextgreatthing. Eventhoughthisguidetakesyouthrougheverystepofbuildingasimpleapp,tobenefitmostithelpstobe acquaintedwithcomputerprogrammingingeneralandwithobject-orientedprogramminginparticular. 2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 6 Setup GettheTools Get the Tools Beforeyoucanstartdevelopinggreatapps,setupadevelopmentenvironmenttoworkinandmakesureyou havetherighttools. App Store Xcode Download TodevelopiOSapps,youneed: ● AMaccomputerrunningOSX10.7(Lion)orlater ● Xcode ● iOSSDK XcodeisApple’sintegrateddevelopmentenvironment(IDE).Xcodeincludesasourceeditor,agraphicaluser interfaceeditor,andmanyotherfeatures.TheiOSSDKextendstheXcodetoolsettoincludethetools,compilers, andframeworksyouneedspecificallyforiOSdevelopment. YoucandownloadthelatestversionofXcodeforfreefromtheAppStoreonyourMac.(TheAppStoreappis installedwithOSXversion10.7andlater.IfyouhaveanearlierversionofOSX,youneedtoupgrade.)TheiOS SDKisincludedwithXcode. TodownloadthelatestversionofXcode 1. OpentheAppStoreapponyourMac(bydefaultit’sintheDock). 2. Inthesearchfieldinthetop-rightcorner,typeXcodeandpresstheReturnkey. 3. ClickFree . Xcodeisdownloadedintoyour/Applicationsdirectory. 2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 7 Tutorial: Basics Thistutorialtakesyouthroughthebasicsofwhatanappis,totheprocessofcreatingasimpleuserinterface, andontoaddingthecustombehaviorthattransformstheinterfaceintoaworkingapp. FollowthistutorialtolearnthebasicsofiOSappdevelopment,including: ● HowtouseXcodetocreateandmanageaproject ● HowtoidentifythekeypiecesofanXcodeproject ● Howtoaddstandarduserinterfaceelementstoyourapp ● Howtobuildandrunyourapp Afteryoufinishthetutorial,you’llhaveanappthatlookssomethinglikethis: Tokeepthingssimple,thetutorialprojecthasonlyaniPhoneinterface,butyouusetheexactsametoolsand techniquestodevelopaniPadapp.ThistutorialusesXcode5.0andiOSSDK7.0. 2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 8 Tutorial:Basics CreateaNewProject Create a New Project Togetstarteddevelopingyourapp,createanewXcodeproject. Xcodeincludesseveralbuilt-inapptemplatesthatyoucanusetodevelopcommonstylesofiOSapps,such asgames,appswithtab-basednavigation,andtable-view-basedapps.Mostofthesetemplateshave preconfiguredinterfaceandsourcecodefilesforyoutostartworkingwith.Forthistutorial,you’llstartwith themostbasictemplate:EmptyApplication. WorkingwiththeEmptyApplicationtemplatewillhelpyouunderstandthebasicstructureofaniOSappand howcontentgetsonscreen.Afteryou’velearnedhoweverythingworks,youcanuseoneoftheothertemplates foryourownapptosaveyourselfsomeconfigurationtime. Tocreateanewemptyproject 1. OpenXcodefromthe/Applicationsdirectory. TheXcodewelcomewindowappears. Ifaprojectwindowappearsinsteadofthewelcomewindow,don’tworry—youprobablycreatedoropened aprojectinXcodepreviously.Justusethemenuiteminthenextsteptocreatetheproject. 2. Inthewelcomewindow,click“CreateanewXcodeproject”(orchooseFile>New>Project). 2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 9 Tutorial:Basics CreateaNewProject Xcodeopensanewwindowanddisplaysadialoginwhichyoucanchooseatemplate. 3. IntheiOSsectionattheleftofthedialog,selectApplication. 4. Inthemainareaofthedialog,clickEmptyApplicationandthenclickNext. 5. Inthedialogthatappears,nameyourappandchooseadditionaloptionsforyourproject. Usethefollowingvalues: ● ProductName:ToDoList 2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 10
Description: