Solutions
Get detailed, in-depth walkthroughs for all the challenges you face in Swift for Complete Beginners, SwiftData by Example, and the 100 Days of SwiftUI. Remember, it's important you attempt each challenge before seeing my solution.
Swift for Complete Beginners
Solutions for the checkpoint challenges you'll encounter as you're learning.
1. Checkpoint 1
Checkpoint 1 of Swift for Complete Beginners asks you to create an Xcode playground able to convert any value of Celsius into Fahrenheit, then print the result. Let’s solve that now…
2. Checkpoint 2
Checkpoint 2 of Swift for Complete Beginners asks you to print the number of items in a string array, then print the number of unique items. Let’s solve that now…
3. Checkpoint 3
Checkpoint 3 of Swift for Complete Beginners asks you to tackle the classic FizzBuzz problem, printing Fizz, Buzz, FizzBuzz, or a number depending on the input. Let’s solve that now…
4. Checkpoint 4
Checkpoint 4 of Swift for Complete Beginners asks you to find the integer square root an input number within a certain range, or throw errors if you can’t do it. Let’s solve that now…
5. Checkpoint 5
Checkpoint 5 of Swift for Complete Beginners asks you to process an array of numbers using filter()
, sorted()
, and map()
. Let’s solve that now…
6. Checkpoint 6
Checkpoint 6 of Swift for Complete Beginners asks you to create a struct to model a car, adding properties and methods that make sense. Let’s solve that now…
7. Checkpoint 7
Checkpoint 7 of Swift for Complete Beginners asks you to create a class hierarchy to store various types of animals, including properties, methods, and initializers. Let’s solve that now…
8. Checkpoint 8
Checkpoint 8 of Swift for Complete Beginners asks you to design a protocol to represent a building, then create two structs conforming to it. Let’s solve that now…
9. Checkpoint 9
Checkpoint 9 of Swift for Complete Beginners asks you to write a function to pick a number from an optional array, or return a random number if that’s not possible. Let’s solve that now…
100 Days of SwiftUI
Solutions for the challenges and milestones you'll encounter as you're learning.
1. WeSplit
There are three challenges for WeSplit, including adding section headers and showing a grand total. Let’s solve them now…
This early challenge day asks you to build a converter app that’s able to move between any two similar units, such as kilometers and miles. Let’s solve it now, then we’ll take it further, and then we’ll take it even further…
This challenge asks you to add some important features to Guess the Flag, including a score tracker and a limited number of questions. Let’s solve those now, and tackle a bonus problem at the end just for fun…
This challenge asks you to go back and adjust both project 1 and project 2 based on what you learned, then try your hand at creating a custom view modifier. Let’s tackle it now…
This challenge asks you to build a fun brain game using all the SwiftUI skills you’ve learned so far. Let’s tackle it now…
6. BetterRest
This challenge asks you to adjust the BetterRest user interface to have sections, a picker, and an always-present bedtime calculation. Let’s tackle it now…
This challenge asks you to disallow certain words, let users start a new game whenever they want, and also track player scores. Let’s tackle it now…
8. Animations
This challenge asks you to add three different animations to the Guess the Flag game from project 2: spinning, fading, and one of your choosing. Let’s tackle it now…
9. iExpense
This challenge asks you to support the user’s preferred currency symbol, style your expenses somehow, then split the list into two sections. Let’s tackle it now…
10. Moonshot
This challenge asks you to add some extra text to the mission view, break up at least two SwiftUI views, then, for something harder, allow the user to move between a grid and a list for missions. Let’s tackle it now…
11. Navigation
This challenge asks you to switch both iExpense and Moonshot over to using what you've learned about navigation. Let’s tackle it now…
12. Habit tracking
This challenge asks you to create a habit-tracking app, optionally with Codable
support and completion count. Let’s tackle it now…
13. Cupcake Corner
This challenge asks you to upgrade the form validation, add a user-facing error, then make the app remember the user's delivery details using UserDefaults
. Let’s tackle it now…
14. Bookworm
This challenge asks you to make sure all book data is provided, to highlight bad books somehow, and to show a date for when each book was read. Let’s tackle it now…
15. SwiftData
This challenge asks you to upgrade iExpense to use SwiftData, adding sorting and filtering at the same time. Let’s tackle it now…
This challenge asks you to create an app that downloads and decodes JSON from the internet, then shows it in a list. Let’s tackle it now…
This challenge asks you to upgrade our simple Friendface app to make it store a SwiftData cache, so it works just as well offline as online. Let’s tackle it now…
18. Instafilter
This challenge asks you to disable options when they don't make sense, add more sliders to control effects, and add three extra filters of your choice. Let’s tackle it now…
19. Bucket List
This challenge asks you to let users switch map styles, show alerts for authentication errors, and create a view model for EditView
. Let’s tackle it now…
20. Accessibility
This challenge asks you to make decorative decorations, make the rows in iExpense read more smoothly with VoiceOver, then conduct your own review of Moonshot and fix it up. Let’s tackle it now…
21. Hot Prospects
This challenge asks you to add an icon to show which prospects have been contacted, to add an editing screen for contacts, and to enable custom sorting for the data. Let’s tackle it now…
22. Flashzilla
This challenge asks you to clear the text fields after adding a card, avoid red flashes when changing your mind about a correct card, and reinsert wrong answers back into the deck. Let’s tackle it now…
This challenge asks you make views fade out, scale down, and change their color, all synchronized with the movement in our ScrollView
. Let’s tackle it now…
24. High Rollers
This challenge asks you build an app that simulates random dice rolls on behalf the user, adding haptic feedback to bring it to life, and permanent storage for later reference. Let’s tackle it now…
25. SnowSeeker
This challenge asks you add a photo credit to resort images, handle loading and saving of favorite resorts, then add sorting options to the main listing. Let’s tackle it now…
26. Drawing
This challenge asks you to add create a custom arrow shape, make it animatable, then create a color cycling rectangle with controls for gradient angle. Let’s tackle it now…
27. Core Data
This challenge asks you to adjust FilteredList
in three ways: make it accept a string predicate, make it accept an enum predicate, then make it accept an array of sort descriptors for the managed object it uses. Let’s tackle it now…
SwiftData by Example
Solutions for the challenges presented at the end of the introductory project in SwiftData by Example.
1. iTour
In my book SwiftData by Example we build a complete introductory project with SwiftUI and SwiftData. At the end I lay out three challenges to help you build your skills further, and we'll solve them here – then go on to solve five bonus challenges too!