Tag: SwiftUI
-
Rock, Paper Scissors (2)
When I was forced by a deadline into delivering this project, I noted in its post that there was a number of improvements to make: Here’s the progress The rock paper scissors could be some better data structure than an array and some ints Done. Made a sweet swifty enum. Read about it here. That…
-
.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…
-
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…
-
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…
-
@ObservedObject v @StateObject
The Youtube algorithm thinks I need to watch more MVVM videos, and it turns out it’s probably right. A day or two ago in an MVVM post using a super simple example, I stored the view model as a property of the view using the @ObservedObject wrapper, as I created it. But then today, Youtube…
-
Simple MVVM
MVVM (Model-View-View Model) is an architectural pattern for apps that separates the data (Model) from the user interface (View). The communication between these two parts is facilitated by a View Model. Model <-> View Model <-> View Model The Model is platform independent – we should be able to pluck it out and add it…
-
@ScaledMetric
I solved the problem (well, I googled a stackoverflow result to the problem) in the previous post about the different heights of the SF Symbols. The answer was to put them in a frame and lock the height. A problem that then arises from that is that when the user changes the text size, they’ll…