Category: Posts
-
.self in ForEach
I’m on Day 25 of Hacking With SwiftUI, and Paul is making a point about how SwiftUI can loop over an array to build a view. He starts with this: But then proposes an alternative: He explains the use of \.self here by saying So, we come back to how Swift can identify values in…
-
I git it*
This meme’s been trending in the r/ProgrammerHumor subreddit, and although “to do literally anything” is a stretch, my git / github workflow is pretty routine now using the relevant xkcd method, but actually with quite a bit of understanding from the first half of the excellent Pro Git book. I highly recommend it. I had…
-
Project 3
This one’s not really a project, just a couple of little updates to earlier work, and a code snippet. Challenge 1 Go back to project 1 and use a conditional modifier to change the total amount text view to red if the user selects a 0% tip. The first one is pretty simple – a…
-
Sean != Erica
When Swift was newer, there was a bunch of podcasts about it – in early episodes of Fireside Swift the existence of a Swift Podcast Network is often mentioned, but now it’s more of an established language there’s a bit less current content to listen to, and what there is, is less focused on learning…
-
Day 23 – Views and Modifiers – Part 4
Then the last trick for for decomposing the views, is to remember we can pass values when we init a struct. So something like this: This is probably my favourite – because although in this example I’ve created the mini-view struct in the body, if it’s a building block I can use elsewhere in a…
-
Day 23 – Views and Modifiers – Part 3
The next part of day 23 started to make my brain hurt a bit. It’s easy to imagine that when presenting a complex screen – perhaps some data from a source as a mixture of images and text loaded from a database into a scroll-able view, that the view may start to get complex. Then…
-
Day 23 – Views and Modifiers – Part 2
Although “immutable” the view structs can contain some control statements such as if/then and for loops. So this is quite legal, and useful. But Paul cautions against this, saying: You can often use regular if conditions to return different views based on some state, but this actually creates more work for SwiftUI – rather than…
-
Day 23 – Views and Modifiers – Part 1
I found this one of the trickier days, so I’ll write it out to clear up my thinking. To draw to to screen in SwiftUI, we don’t call a command to draw on a canvas or window. Rather, a view is defined as an immutable struct of type some View. Here’s the simple one from…
-
Project 2 – Guess the Flag
Another 100 Days project – the second tutorial one. This was once again a “V” design pattern (put everything in the view) and as I kept growing it, especially in the challenges, I had a growing sense of unease. New things for me was how image assets work – identifying them with strings is convenient,…
-
Download a Directory from a GitHub Repo
For Challenge 2 in the 100 days, I needed to download a directory of flag images from Paul’s GitHub. He has all the projects as sub-directories of a single “Hacking With Swift” repo. I didn’t need to whole thing, just the directory with the images. Strangely, git does not have any simple way of doing…