I’m going to add a readable name to each existing type of HorizontalAlignment
. This isn’t actually an enum, but I’m going to want to iterate through these cases and display the name of each of the default options.
The way I’ve gone about this is somewhat verbose, because I wanted to make it clear that .listRowSeparatorLeading
and .listRowSeparatorTrailing
are exclusive to iOS 16.
Now I want to conform to a few Apple protocols.
These will make it possible for me to create a Picker
that can easily select from these alignment types.
I’m going to make a Grid
that contains 3 rows.
The first row has a border that starts bright red and gets gradually darker. Before the first cell there is a Text
that says Aligned, and this has the alignment we will be modifying applied to it. Row B has a border that starts bright green and gets gradually darker. It has a thin Rectangle
at the end of its row, which will show the actual location of the alignment guide being used.
You might notice that there isn’t yet a way to change the alignment currently being displayed.
Let’s change that!
This is where we really benefit from those extensions to HorizontalAlignment
. The Identifiable
protocol makes it possible to use it directly in a ForEach, and Hashable
makes it possible to use it as a tag. CaseIterable required that there was an array called allCases, although I suppose this could’ve been added without conforming to the protocol.
The name was certainly not required by a protocol, but this made it easier to display the current alignment in the Picker
.
Last Week’s Daily Coding Tips
You might notice there weren’t any Daily Coding Tips last week.
I’ve been traveling again, but my main 2017 MacBook Pro has fallen victim to Flexgate and is not one of the models Apple will fix as part of their repair program. The Apple Store actually quoted a cost of over £650 ($760) to fix my display backlight, which only works when the laptop is around 50% closed (not exactly an ideal viewing angle).
I’ve been making do with a 1.8 GHz 2017 MacBook Air with 8 GB, but the complexity of this tutorial has made it difficult to establish whether the Xcode beta is crashing or just building the app extremely slowly.
Hopefully I will be back to doing Daily Coding Tips from today onwards.