Fernando Olivares

August 9, 2023

What is a View?

I obviously understand what is a View. In its most technical sense, a View is a protocol that has an associated type body which conforms to View. The interesting part of the question is, is a View still a View when you modify it? For example, a Text View that has its opacity reduced, is it still a View? Well, yes. If the question asked...
Read more
August 9, 2023

Understanding SwiftUI property wrappers

I just finished Chapter 3 of Thinking in SwiftUI and I need to wrap my brain around property wrappers. For one, I find it funny how Objective-C'y it feels to have a property wrapper. This pattern of synthetization and property declaration is very similar to what we had in Objective-C. I think I need to summarize what each property wrap...
Read more
August 8, 2023

Part 2: struct View vs @ViewBuilder

In one of my previous posts, I tried to figure out what to do with subviews in SwiftUI. There's four ways of building subviews for SwiftUI: 1. Building the subview embedded directly into the parent's body. • This will usually happen for structural subviews (e.g. HStack or Vstack) and for simpler subviews. 2. Building the subview as a n...
Read more
August 8, 2023

What is the difference between an autoclosure and a closure that is evaluated depending on conditions?

While learning SwiftUI using the excellent "Thinking in SwiftUI" book by obc.io authors, I ran into this example (emphasis mine): “1. The counter view is created, but the value of the state object isn't present yet, because the initial value is stored as an autoclosure.” I kept on reading but I got the annoying feeling that I shouldn't...
Read more
August 6, 2023

struct View vs @ViewBuilder

I've finally started learning SwiftUI by reading "Thinking in SwiftUI" from objc.io. I hadn't even gone a chapter when I realized I didn't understand what the difference was between a property that is a view, a property that is marked as @ViewBuilder and a function that is marked @ViewBuilder. First, thanks to the book, I understood th...
Read more