Day 22
Day 22 ๊ด๋ จ
Project 2, part 3
In this project youโve learned about images, stacks, gradients, buttons, and more, along with a whole host of new modifiers to help bring your UI designs to life.
All of these skills will come in useful in your own SwiftUI apps โ not maybe or might, but will. As Dr Seuss said, โthe more that you read, the more things you will know; the more that you learn, the more places you'll go.โ And thatโs what this course is about: giving you the ability to go anywhere with SwiftUI, and build whatever apps help you reach your goals.
Before we move on to the next topic, itโs time to pause and review: did you fully understand everything you learned? That means another test, but it also means three more coding challenges to make sure youโre writing your own code as often as possible.
Today you should work through the wrap up chapter for project 2, complete its review, then work through all three of its challenges.
Guess the Flag: Wrap up
Guess the Flag: Wrap up
Thatโs another SwiftUI app completed, including lots of important new techniques. Youโll use VStack
, HStack
, and ZStack
in almost every project you make, and youโll find you can quickly build complex layouts by combining them together.
Many people find SwiftUIโs way of showing alerts a little odd at first: creating it, adding a condition, then simply triggering that condition at some point in the future seems like a lot more work than just asking the alert to show itself. But like I said, itโs important that our views always be a reflection of our program state, and that rules out us just showing alerts whenever we want to.
Review what you learned
Anyone can sit through a tutorial, but it takes actual work to remember what was taught. Itโs my job to make sure you take as much from these tutorials as possible, so Iโve prepared a short review to help you check your learning.
Click here to review what you learned in this project.
Challenge
One of the best ways to learn is to write your own code as often as possible, so here are three ways you should try extending this app to make sure you fully understand whatโs going on:
- Add an
@State
property to store the userโs score, modify it when they get an answer right or wrong, then display it in the alert and in the score label. - When someone chooses the wrong flag, tell them their mistake in your alert message โ something like โWrong! Thatโs the flag of France,โ for example.
- Make the game show only 8 questions, at which point they see a final alert judging their score and can restart the game.
Note: That last one takes a little more thinking than the others. A good place to start would be to add a second alert()
modifier watching a different Boolean property, then connect its button to a reset()
method to set the game back to its initial state.
Guess the Flag: Wrap up - Additional
Once youโre done, tell other people: youโve completed your second SwiftUI project, youโve passed the test, and youโve even extended it with your own code.
You should be proud of what youโve accomplished โ good job!