Tag: code
-
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…
-
Challenge 1
I’m up to Challenge 1 of 100 Days of SwiftUI (Day 19) which is to make your own simple (no MVVM) version of the app built in the previous three days. It’s about as simple as can be whilst still feeling like a real app. Something I hadn’t done before was limiting the keyboard to…
-
Codewars / reduce
codewars.com is a “coding practice” website. You chose a language and a skill level, then it offers up a task (or kata) for you to write a suitable function. The first one it gave me was seemed too hard, so I changed my level to beginner and skipped to the next one. This was my…
-
Named Loops
Here’s a neat thing I haven’t seen before. Other languages I’ve worked in haven’t had a neat way to break out of a set of nested loops to a particular loop. It’s not an issue that comes up a lot, but when it has I’ve solved it by creating a continue flag and having that…
-
Checkpoint 9
-
Checkpoint 8
-
Protocols
The evolution of structs into class-like things that can hold properties and methods in Swift raised in my mind “what about inheritance?” – but no: structs in Swift can not use inheritance. Swift classes implement inheritance, but only from one class; there’s no multiple inheritance. Protocols neatly address both these concerns to a large extent,…
-
Checkpoint 7
-
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…