Lesson 7 of Module 4 was a walkthrough of creating a swipeable “featured view” for the Recipe App that we’re creating in the module. Both educational and bewildering at the same time. Bewildering in that there are so many options, but educational in that it appears “easy” to do.
The necessary thing here is, as with much of this, to get an understanding that things can be done rather than trying to cram how everything is done into the limited capacity we have for learning.
The challenge this time around was to implement a swipeable card system (like the featured view), but with 50 numbered cards (numbered from 1-50, numbers circled in black) with a random colour selected for the card background.
I had my usual stumble on figuring out how For/ForEach works with SwiftUI (apparently ForEach(1...50)
doesn’t work by ForEach(1..<51)
does. I’m sure that makes sense to someone.
You can determine your own colour using .foregroundColor(Color(.sRGB, red: ..., green: ..., blue: ..., opacity: ...))
but the RGB colours are taken from 0 to 1, not 0 to 255 like most sensible people would understand it to be. I’m sure that makes sense to someone, too.
On comparison with the solution, I noticed that the numbered circles 1-50 all exist in the SF Symbols library. I guess I was supposed to figure that out. I “foolishly” just took an empty circle from the library and display the number over it separately.
Although, officially, that’s wrong, a simple alteration of the ForEach
loop enables me to change my cards to go up to any number whilst the “solution” breaks at 51 and above because there is no SF Symbol for numbers higher than 50. Not that I knew that (I didn’t) because it just didn’t occur to me that there would be all those circled numbers in the library in the first place. Who’d even think there was? I guess it makes sense to someone.
You can probably tell from this post that I’m wading through the learning process at the moment, with so much information floating around me that I’m hesitant to go seeking “new stuff” (like the aforementioned SF Symbols library) and would prefer to just use what we’ve been learning to reinforce that which we’ve learnt.
Somedays the mountain I’m climbing seems steeper than others, but I guess it doesn’t matter which road you travel so long as you get to the same destination.