Day 205
100 Days of SwiftUI – Day 19
This day was dedicated to creating our own app from scratch in the form of a Unit Converter. I have some plans on writing about that so I didn’t create a blog post about it yet. Stay tuned for news.
Day 206
100 Days of SwiftUI – Day 20
In this day we learned some more basics of SwiftUI, in particular how to use Stacks, Buttons, Alerts, Colors, Frames, Gradients and more.
You can find the project with all the explanations in comments at this link.
100 Days of SwiftUI – Day 21
In this day we created a whole game from scratch, a guess-the-flag game that was super-fun to create! This is the same as Project 2 of Hacking with Swift but SwiftUI allowed for some very nice graphical tweaks to make the game much more beautiful than it would have been in UIKit with the same lines of code. Of course everything is possible but, I start to see why SwiftUI will be the future.
You can find the project in its current state at the same link posted above, just a few commits beyond.
Day 207
So difficult to have something done today. I worked four and a half NET hours on the current music notation project I am involved with and then had to clean so many things in the house. Freelancer life is wonderful, just sometimes very hard to stay on tracks with the things you have to do.
100 Days of SwiftUI – Day 22
Review
ZStack
lets us layer views on top of each other. The Z refers to Z index, which is how we refer to depth in 3D graphics- Semantic colors are colors that are named according to their use rather than according to their hue (sfumatura in Italian). For example,
color.primary
might be light or dark depending on the device theme. - Gradients can be created using an array of colors or an array of color stops. Color stops include both a color and a position inside the gradient. It is not yet totally clear to me how we create and use color stops and what they are in practice.
- Colors are views in SwiftUI. This allows us to use them directly inside stacks.
- The
frame()
modifier lets us specify a precise width and height for a view but we don’t need to specify both width and height if we don’t want to. - SwiftUI let’s us draw shadows with a specific color and radius. If we use bright colours we can use this to create glow effects.
- The safe area excludes any space allocated to the home indicator as well as excluding the status bar.
- Buttons can be plain text, they can have images, or they can have other kinds of views. We can use multiple views by placing them inside a stack.
- Buttons must be given a closure to be run when they are tapped. Without some sort of action to run, the button would be pointless.
- The
Int.random(in:)
method chooses one random integer in a range we specify.. We can use closed ranges or half-open ranges, depending on what we need. - We can embed a
HStack
inside aVStack
. This lets us make grid structures fairly easily. - We can draw borders with a custom shape by using the
overlay()
modifier. We can apply separate modifiers to that overlay, such as a border.
Challenges
Challenge 1: 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.
- First: add an
@State private var score = 0
statement in the properties section of the file. - Second: in the
flagTapped(_:)
method, add ascore += 1
to theif
statement and ascore -= 1
to theelse
part. - Third: inside the
Alert()
change themessage
to beText("Your score is \(score)"
That’s it!
Challenge 2: show the player’s current score in a label directly below the flags.
- I tried to have as much fun as possible here: I created a
Text("Score: \(score)"
and then added the following modifiers:- a
.foregroundColor(.white)
to make it stand out against the background. - a
.font(.title)
to make it big! - a
.fontWeight(.heavy)
to make it super bold but not as bold as the title - Finally, a
.shadow(color: .yellow, radius: 4)
, which makes it sparkling!
- a
The great thing here is how the label updates immediately without needing extra work! In UIKit, this was much harder, even if, for the brain, it was probably better! If we only get to know this, our brain will never work enough on things and when a real problem will hit … BUM! We will be on the floor!
Challenge 3: 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.
- In the
flagTapped(_:)
method, in theelse
statement, change thescoreTitle
to be"Wrong!\nThat's the flag of \(countries[number])!"
That’s it!
It is not 11.36pm on October 15th and, in a few minutes, it will be my birthday so I don’t want to stay up more! Tomorrow I will have the heaviest of days in teaching but I will try to see if the equivalent in the 100 Days of Swift had some more challenges to add!
Goodnight, world!

Thank you for reading!
If you like what I’m doing here please consider liking this article and sharing it with some of your peers. If you are feeling like being really awesome, please consider making a small donation to support my studies and my writing (please appreciate that I am not using advertisement on my articles).
If you are interested in my music publications don’t forget visit my Facebook page and the pages where I publish my scores (Gumroad, SheetMusicPlus e ScoreExchange).
You can also support me by buying Paul Hudson’s book from this Affiliate Link.
Anyways, thank you so much for reading!
Till the next one!