Develop In Swift

Transcription

Develop in SwiftSwift Coding Club

Welcome to the Swift Coding Club!Learning to code teaches you how to solve problems and work with others increative ways. And it helps you bring your ideas to life.Swift Coding Clubs are an excellent way to learn to code and design apps.Activities built around Swift, Apple’s coding language, help you collaborateas you learn to code, prototype apps, and think about how code can make adifference in the world around you.You don’t have to be an educator or a programmer to run a Swift Coding Club.The materials are self-paced, so you can even learn alongside your club members.And you can all celebrate your club’s ideas and designs with an app showcaseevent for your community.Coding ResourcesSwift Coding Clubs are built arounda variety of resources for learning tocode. Apple takes coders from learningthe basics on iPad to building real appson Mac.Everyone Can Code Ages 10 Use Swift code to learn codingfundamentals with Swift Playgroundson iPad. Find out more about theEveryone Can Code curriculum This guide is arranged in three sections:Develop in Swift Ages 14 Get StartedLearn and ApplyCelebrateEverything youneed to launch aSwift Coding Club.Modules andactivities forclub sessions.Helpful resourcesto plan and host acommunity event.WelcomeLearn to develop apps in Xcode onMac. Find out more about theDevelop in Swift offering Learn to Code with AppleYou don’t need prior experience todive right into creating apps for Appleplatforms. Apple’s app developmentcurriculum makes it easy for anyone tocode in Swift just like the pros—whetherit’s for a semester in school, forprofessional certification, or to advanceyour skills. Learn more 2

Get Started1. Explore Develop in Swift resourcesDevelop in Swift materials teach you how to use Xcode on Mac and Swift, a powerful and intuitive open source programminglanguage designed by Apple. It’s the same language professional developers are using in the fast-growing app economy tomake apps for iOS, macOS, tvOS, iPadOS, watchOS, and beyond. And it’s great for inspiring club members who are both new tocoding and those with experience. Before you start designing your club experience, explore these Develop in Swift resources.XcodeXcode is an integrated development environmentprofessional developers use to build real apps. It givesyou the tools you need to create a complete app—fromdesigning your user interface (UI) and implementingcode to testing and debugging your app and provisioningit for distribution on the App Store.Develop in Swift ExplorationsDownload Xcode Download Develop in Swift Explorations Learn key computing concepts for building a solidfoundation in programming with Swift. Learn about theimpact of computing and apps on society, economies, andcultures while exploring iOS app development. Lessonstake you through the app design process: brainstorming,planning, prototyping, and evaluating an app of your own.Download Develop in Swift Explorations Teacher Guide Get Started3

2. Check your tech3. Make a planBe sure you have the following before your first meeting:Here are some things to consider: Mac. You’ll need a Mac running macOS Big Sur or later.It’s best if each club participant has their own Mac. Youcan also share and code together. Who are your club members? What are their interests?Do they have experience with coding, or are theybrand-new to it? Xcode 12. This free Mac app from Apple is used to buildevery Mac app and every iOS app, too. Xcode hasall the tools needed for creating an amazing app. How often will your club meet? How many hours ofcoding activities will you have? Develop in Swift Explorations. This free resourcefrom Apple guides new coders through key computingconcepts to build a solid foundation in programmingwith Swift. What technology is available for the club? What are the goals of your club? Keynote. You’ll use this app on Mac for your designingyour app prototypes.Visit Apple Support to get help with Apple products.Get Started4

4. Spread the wordLet people know about your Swift Coding Club. Here are some ideas andresources to attract new members to your club: Announce your club. Use email, social media, the web, flyers, or word ofmouth to let your community know about your club. Host an informational meeting. Ask potential club members about theirinterests and the types of projects they’d want to create. Talk about ideasfor holding community events and how they can get involved.You can also share a short video about the club online or on social media.Swift Coding Club posterThe items below can help you promote and personalize your Swift Coding Club: Posters. Download this free template, then personalize it to create your ownposter. Print and display it, or make a digital poster to share online. Be sureto include details for when and where the club will meet and how to join. Stickers and T-shirts. Use these Swift Coding Club stickers to help promoteyour club. T-shirts are a great way to recognize members who participate inapp showcase events. Download the Swift Coding Club T-shirt template tomake shirts for your members.Swift Coding Club stickerSwift Coding Club T-shirtGet Started5

Tips for club leadersBuild a leadership team. Havinga group of members who helpwith leading the club can make itmuch easier and more fun. Which clubmembers have leadership potential?Think about adding officers to your clubfor events, coding, app design, and more.Learn together. Club leaders don’thave to know everything. Help yourmembers work on their own researchand problem-solving skills andencourage them to help others.Share ideas. Some members will beinterested in making games. Others mightwant to create apps to help people, learnSwift, or control robots. Think about waysfor members to work together on projectsthey care about.Mix it up. Sometimes members who aremore advanced can leave others behind.See if those members can partner up withbeginners for pair programming. Teachingsomeone else is a great way to learn!Show off. An app showcase eventis a great way to promote your club,app ideas, and coding skills to friends,families, educators, and the community.It might even help you recruit moremembers. See page 12 to get tips forholding your own app showcase.Get Started6

Learn and Apply1. Learn about SwiftSwift is a powerful and intuitive programming language created by Apple for buildingapps. It’s the same language professional developers are using in the fast-growingapp economy to make apps for iPad, Mac, Apple TV, Apple Watch, and more. Swiftmakes programming easier, more flexible, and more fun.To find out more about Swift, visit swift.org.2.Dive into Xcode and Develop in Swift ExplorationsDownload the Xcode app The club materials are built around app projects for Xcode, an integrateddevelopment environment professional developers use to build real apps. Itincludes a source code editor for writing and managing code, a debugger fordiagnosing problems, and a user interface editor—called Interface Builder—forlaying out the visual elements of the app and connecting them to the code.To find out more about Xcode, visit the Xcode Support page.Develop in Swift Explorations guides learners through playground activities in Xcodeas they learn coding basics. Xcode playgrounds allow you to write Swift code andimmediately see the results in a live preview. Playing with code—and seeing what itdoes—is a great way to get started coding and to experiment with new ideas.Develop in Swift Explorations Teacher Guide includes additional activities you canuse with club members to spark their interest, support their understanding, andinspire them to follow and develop their passions.Download the teacher guide Download Develop in Swift Explorations Teacher Guide Learn and Apply7

Tips for learning with XcodeThere’s no one way towrite code. Membersshould review each other’scode, provide feedback,and help each other debug.Explore Xcodepreferences. Set yourtext editing and otherpreferences by choosingXcode Preferences fromthe menu bar. You canadd developer accounts,customize navigationor fonts, choose certainbehaviors when eventsoccur, and more.Use debugging tools.When your app crashes, ared highlight shows the linein your code where theerror occurred. Use print()in your code to log helpfulinformation to the console.Set breakpoints to pauseyour app, inspect variables,and step through codeline by line.Stop and think. Bugs areinevitable. Stop and thinkabout the problem. Whatare its symptoms? Waseverything working fineuntil [x] occurred?Learn and ApplySet up a help desk.Maintain a space whereclub experts can providesupport to their peers.Take it further. Advanced club memberscan work through the Develop in SwiftExplorations course and focus more oncoding aspects of their Xcode appprototypes.Master keyboard shortcuts.Build and run the project: RComment or uncomment selected code: /Reindent selected code: IShow the inspectors: 0Show documentation: 08

3. Choose your projectsSwift Coding Club materials are organized around app project modules and anapp design challenge. Club members learn programming concepts as theyexplore Xcode by completing a series of playground activities and guided appdevelopment projects. The Develop in Swift Explorations course provideseverything they’ll need to complete each module.The first few app projects require no prior knowledge and then beginto increase in difficulty. Check the complexity of each project, and choosea starting point that’s suited to your club members’ coding experience.The app design challenge is designed to be completed either concurrentlywith another module or as a standalone challenge.Download the course Module 1: PhotoFrame AppModule 2: QuestionBot AppModule 3: ColorMix AppModule 4: ElementQuiz AppModule 5: App Design ChallengeLearn and Apply9

4. App design challengeWhile club members are learning to build apps in Xcode, they can also begin to concept and share ideas for apps they’llwant to build and help prototype ideas, test the app with peers, and refine user experiences. The app design challenge letsthem work beyond their programming skills, unleashing their creativity and ingenuity.Club members will learn about the features of successful apps and what to consider when designing their own. They’ll workthrough the Develop in Swift App Design Workbook to engage in the app design process and develop a working appprototype that they can share through an app showcase. Club members can work on an app project for part of each sessionand their own app idea for the remainder of the sessions, or alternate sessions between projects.Learn and Apply10

5. Take it furtherYou can also add sessions that support your members’ interests. You can expand on designand coding activities by investigating apps for connected devices or for watchOS. Or go deeperinto topics like machine learning and augmented reality to explore the future of app design.To prompt design brainstorming, you might even add guest speakers or field trips to help club.members better understand a project’s audience and design requirements.Run MyCode

CelebrateCommunity event or virtual app showcaseHost a community event or virtual app showcase to involve the broader community and explore the potential of code forsolving challenges they care about. These events are also the perfect way to show off your club members’ talents!1. Plan the big event. Set a date and invite peers,educators, families, and community members.Allow time for each team to present their project andhold a short Q&A session either in person or virtually.If the group is large, you can split the event into tworounds and have members watch each other’spresentations.Consider finishing the event with a fun slideshow ofphotos taken throughout club sessions.2. Design awards. Friendly competition can be a greatmotivator. Inspire club members by offering awards thatrecognize specific strengths in coding and design—forexample: Best Engineering Best Innovation Best Design Best PresentationYou can also encourage audience participation witha People’s Choice award.Develop in SwiftSwift Coding ClubCertificate of AchievementAwarded toForSignatureDateDownload and modify this certificatefor different awards.Celebrate12

3. Recruit judges and mentors. They can be educatorsor staff, peers with expertise in coding, experts from thedeveloper or design industry, local community leaders, orindividuals who would benefit from project ideas.Judges don’t have to wait until the showcase to meet theclub. Consider inviting them as guest speakers to sharetheir knowledge while learners are in the brainstorming orplanning phase of their projects.4. Share and inspire. You may want to record thepresentations. Share them with the broader communityand create a highlight reel to inspire future club members.Celebrate

Develop in SwiftSwift Coding ClubCertificate of AchievementAwarded toForSignatureDate

Swift Coding Club ModulesModule 1: PhotoFrame AppModule 2: QuestionBot AppModule 3: ColorMix AppModule 4: ElementQuiz AppModule 5: App Design Challenge

PhotoFrame AppModule 1

PhotoFrame AppModule 1 OverviewFind out just how easy it is to build your very first app. In this module, you’ll learnthe key concepts and skills you need to build an app that can display basic UIcomponents such as a photo. Understanding the basics of UI components iscritical to creating any app, so it will come in handy as you expand your codingand app development skills. With this project, you’ll also familiarize yourself withXcode, Interface Builder, and Simulator, and you’ll learn how to use them togetherto build your own apps.Sessions 1–7Learn about values and experiment with values, variables, and constants inXcode playgrounds. Playground Basics Naming and Identifiers Strings Constants and VariablesSessions 8–9Apply new skills and concepts to create a word game playground.Sessions 10–12Build a PhotoFrame app in Xcode and Interface Builder.PhotoFrame App17

PhotoFrame App1Get Started with XcodeFind your way around Xcode playgrounds,and learn how to enter and change codein basic programs.Get Started: Explore programmingbasics and the roles of data inputs andoutputs.What is Programming? (page 15)Values (page 16-17)2–3Naming and IdentifiersLearn about the importance of namingin programming, and build some simpleprograms to solve problems.Get Started: Find out why naming andidentifiers are important, and name keycomponents for a new game as yousketch your design for it.4–5StringsLearn about strings and how to use themin your code to create a simple game.Get Started: Identify key properties ofstrings, and create your own chatbotresponses.Strings (page 20-21)Naming and Identifiers (pages 18–19)Play: Build a fill-in-the-blanks game.Play: Learn how to enter and changecode.Playground Basics playground(pages 27–29)PhotoFrame AppPlay: Practice your naming skills asyou build programs to solve simpleproblems.Strings playground(pages 38–40)Naming and Identifiers playground(pages 30–33)18

PhotoFrame App6–7Constants and VariableLearn how to declare variables andconstants, and build a program to keeptrack of a score.Get Started: Compare variables andconstants, and imagine your life as aprogram.8–9Word Games10–12PhotoFrame AppUse your knowledge of values,constants, and strings to create wordgames in playgrounds, then have clubmembers try them out.Find your way around Xcode InterfaceBuilder, and build and run a simple app.Apply: Build a word-substitution gamethat results in funny stories.Apply: Build and view an app thatdisplays a custom-framed photo.Word Games playground (pages 45–46)PhotoFrame app project (pages 48–73)Constants and Variables (pages 22)Play: Build a program to help you tracka game scoreConstants and Variables playground(pages 41–44)PhotoFrame App19

QuestionBot AppModule 2Design an App20

QuestionBot AppModule 2 OverviewHave you ever used a quiz app or wondered how Siri works? All apps have internal logicthat defines their behavior. With QuestionBot, you’ll build an app containing the “brain”of a bot that responds differently to different questions. To do that, you’ll learn how todesign algorithms, group code in functions, use different types, and more. This modulehelps you focus on understanding how apps work, learn about creating the code thatcontrols the interface of an app, and explore logic you can use to make an app mimichuman intelligence.Sessions 1–10Learn about algorithms as the cornerstone of programming, and experiment withfunctions, types, and parameters in Xcode playgrounds. Algorithms Functions Types Parameters Making Decisions with BooleansSessions 11–12Apply new skills and concepts to create dance routines in the BoogieBot playground.Sessions 13–14In Xcode, add functionality to program the “brain” of a QuestionBot app to answerquestions.QuestionBot App21

QuestionBot App1–2Algorithms3–4Functions5–6TypesLearn about algorithms as a keyprogramming tool, and practicedesigning algorithms to solve everydayproblems.Learn about functions for creatingreusable sections of code, and builda song maker.Learn about types as a way to distinguishdifferent types of data, and build aprogram to perform simple calculations.Get Started: Use sequencing andselection in algorithms to solve simpleproblems, and design an algorithmfor a program that matches music toyour mood.Get Started: Practice groupinginstructions under functions in afamiliar context, like preparing dinner.Get Started: Explore types as a way ofdescribing values and consider the typesof parts you’d use in a construction task.Functions (pages 112–114)Types (pages 115–116)Play: Build a program that makes arepetitive song.Play: Build a program to complete simplecalculations.Functions playground (pages 121–124)Types playground (pages 125–127)Algorithms (page 109)Sequencing (page 110)Selection (page 111)QuestionBot App22

QuestionBot App7–8ParametersLearn about using parameters to defineinputs to functions, and build a programthat outputs different sentences basedon the values you enter.Get Started: Use parameters to makeyour functions more flexible, and refineyour dinner preparation functions toaccommodate specific requirements.Parameters (pages 116–117)Play: Build a program that usesfunctions to output a different sentencebased on the values you pass into it.Parameters and Results playground(pages 128–130)QuestionBot App9–10Making Decisionswith BooleansLearn about how powerful the Booleantype can be in programming, and build aprogram to determine if a given year willbe a leap year.11–12BoogieBotUse functions to build complex danceroutines out of smaller parts, and shareyour choreography with others asanimated images.Get Started: Explore Booleans anduse them to help a robot out of a trickysituation.Apply: Create dance routines forBoogieBot and save your creationsas animated images.Making Decisions with Booleans(page 118)BoogieBot playground (page 135)Play: Build a program that determinesif a year is a leap year.Making Decisions playground(pages 131–134)23

QuestionBot App13–14QuestionBotBuild the logic of a QuestionBotapp so that it responds differentlyto different questions.Apply: Program the “brain” of aQuestionBot app to decide how it willanswer questions, and learn how totest and troubleshoot your code.QuestionBot app project (pages 138–150)QuestionBot App24

ColorMix AppModule 3Design an App25

ColorMix AppModule 3 OverviewThink about the iPhone user interface (UI). So far, you’ve built apps from basic UIelements and learned how to create the logic behind the UI. With ColorMix, you’lllearn how to build an interactive app that has controls such as buttons and switches.More importantly, you’ll learn how to connect those visual UI elements to Swift codeso they work the way you want them to. To do this, you’ll learn about defining yourown custom types with properties and methods, using instances of types, andcollecting data in arrays. In the end, you’ll have ColorMix, an app that generates allthe colors of the rainbow—and more—by mixing red, green, and blue.Sessions 1–6Learn about organizing data, experiment with defining methods and properties for acustom type, and work with arrays in Xcode playgrounds. Instances, Methods, and Properties Arrays and Loops StructsSessions 7–8Learn how graphics are created, then build graphics, emoji, and animated linedrawings one pixel at a time.Sessions 9–12Build a ColorMix app by adding switches and sliders to the UI.ColorMix App26

ColorMix App1–2Instances, Methods,and PropertiesLearn to create instances of types andhow to use their methods and properties,and program a robot dance-off.Get Started: Explore how types definemethods and properties, and experimentwith describing methods and propertiesfor different kinds of animals.Instances, Methods, and Properties(page 184)Play: Build a program to set up adance-off between two robots.Instances, Methods, and Propertiesplayground (pages 196–198)ColorMix App3–4Arrays and Loops5–6StructsLearn how to order data in arrays andhow to process arrays using loops,and build a program to tally votes,track progress, and find key words.Learn how to create custom types withstructs, and use a custom type to solvea programming challenge.Get Started: Use iteration in youralgorithms, and use loops to work withelements in arrays. Create an algorithmto describe game play in a board game,and consider the ways you could workwith a collection.Get Started: Define your own types withstructs, and create a custom type for ananimal of your choosing.Defining Your Own Types with Structs(pages 191–192)Lists and Arrays (page 185)Algorithms: Iteration (pages 186–187)Loops (page 188)Working with Arrays—Searching(pages 189–190)Play: Build programs to tally votes, trackyour progress toward a daily goal, andfilter messages for key words.Play: Build a program that uses a customtype to solve a problem.Structures playground (pages 203–205)Arrays and Loops playground(pages 199–202)27

ColorMix App7–8Pixel Art9–12Color PickerLearn how graphics are created, thenbuild your own graphics, one pixel ata time.Learn how to use actions and outletsto connect your Swift code to yourapp’s UI.Apply: Write code to handcraft graphics,emoji, and animated line drawings.Apply: Build an app with switches,sliders, and buttons that lets you mixyour own colors.Pixel Art playground (pages 215–216)ColorMix app project (pages 301–345)ColorMix App28

ElementQuiz AppModule 4Design an App29

ElementQuiz AppModule 4 OverviewMost people use apps to solve a particular problem—to help them get organized,calculate their finances, or get directions, for example. In ElementQuiz, you’ll buildan app that helps you memorize elements in the periodic table. You’ll learn aboutenums, then apply your learning to tackle an independent app challenge of yourchoice. You could build a MemeMaker app, create a Rock, Paper, Scissors game,or take the ElementQuiz app to the next level.Sessions 1–4Follow the steps to build the flash card interface of an ElementQuiz app.Sessions 5–6Learn about enums, and build a program to tally votes. Enums and SwitchSessions 7–12Choose one of three app projects to build.ElementQuiz App30

ElementQuiz App1–4ElementQuiz App:Part ALearn how to build a flash card app thathelps you to memorize elements in theperiodic table.Apply: Build a Quiz app with a flashcard interface that helps users learnthe chemical symbols of elements.ElementQuiz app project, parts 1–3(pages 401–418)ElementQuiz App5–6Enums and SwitchLearn about enums and build a programto tally votes.Play: Build a program that talliesthe results of polls.Enums and Switch playground(pages 206–208)31

ElementQuiz AppFor sessions 7–12, select from one of the following three app projects. Stars indicate level of difficulty.7–12MemeMaker AppLearn how to use segmented controls to displaydifferent captions above and below an image.Since the controls are independent, you canmix and match the text to create customizedcombinations. Learn how to use gesturerecognizers to let the user drag captions aroundthe screen.Apply: Build an app that lets you add funcustomized captions to a photo based onyour mood.MemeMaker app project (pages 384–399)ElementQuiz App32

ElementQuiz App7–12Rock, Paper, Scissors AppLearn how to customize structs and enums tocreate the model and logic for a game of Rock,Paper, Scissors; use random numbers so thatusers can play against the computer endlessly.Apply: Build a game app using emojisand buttons.Rock, Paper, Scissors app project(pages 368–383)ElementQuiz App33

ElementQuiz App7–12ElementQuiz App: Part BLearn how to handle text input to create a scoredquiz mode in the ElementQuiz app. Learn how tostructure user interface logicand how to refactor your code as it becomes morecomplex.Apply: Extend the Quiz app to include a scoredquiz mode.ElementQuiz app project, Parts 4–10(pages 416–467)ElementQuiz App34

App Design ChallengeModule 5Design an App35

App Design ChallengeModule 5 OverviewResourcesIn this module, club members use the Develop in Swift App Design Workbook to design anapp to help solve a challenge they care about. Club participants will use a design thinkingframework to learn app design—a fundamental skill of iOS app development. They willexplore the relationship between app design and coding in Swift through each stage of theapp design cycle to bring their app ideas to life.You can then use the App Showcase Guide to help members plan an app pitch video thatdocuments their process and shows off their app design. Then host an app showcase tocelebrate your club members’ ingenuity.Develop in Swift App Design Workbook ဆí DefineApp Showcase Guide ဂ eattotypeProဃ Iterateဃ stTeကbValidApp Design CycleApp Design Challenge36

App Design ChallengeClub participants form small teams, identify a challenge they care about, then design an app to help solve it. Using the Develop inSwift App Design Workbook, they follow a design process of defining app ideas, building a working prototype in Keynote, and testingand evaluating the app with users before taking their discoveries back to refine their app.ဆíဃ DefinePrototypeDiscover a challengeand the people itaffects. Then analyzeit and plan a detailedsolution.App Design ChallengeMap and build awireframe for thefeatures of your app.Then create a prototypethat adheres to iOSdesign guidelines.ဂ ကbCreate a plan to test yourprototype. Then scriptand prepare to conductyour tests.Gather and organizethe data you collectedin your tests, thenform key insights andconclusions.TestValidateဃIterateMake a plan toaddress the issuesyou discovered byrevisiting specific partsof the design process.37

2021 Apple Inc. All rights reserved. Apple, the Apple logo, Apple TV, Apple Watch, iPad, iPhone, Keynote, Mac, MacBook Pro, macOS, Siri, Swift,Swift Playgrounds, the Swift logo, watchOS, and Xcode are trademarks of Apple Inc., registered in the U.S. and other countries. tvOS is a trademark of Apple Inc.App Store is a service mark of Apple Inc., registered in the U.S. and other countries. IOS is a trademark or registered trademark of Cisco in the U.S. and othercountries and is used under license. Other product and company names mentioned herein may be trademarks of their respective companies. April 2021

Swift is a powerful and intuitive programming language created by Apple for building apps. It’s the same language professional developers are using in the fast-growing app economy to make apps for iPad, Mac, Apple TV, Apple Watch, and more. Swift makes programming easier, more flexible, and more fun. To find out more about