Eager Grids with SwiftUI

Introduction Back in 2020 we got new views to draw grids in SwiftUI (LazyVGrid and LazyHGrid). Two years later, we are getting yet another view to display views in a grid (Grid). However, these new addition is very different, not only in the way you use it, but also how it behaves internally. The views … Read more

Alignment Guides in SwiftUI

Alignment guides are a powerful, but usually underused layout tool. In many cases, they help us avoid more complex options, such as anchor preferences. As you can see in this example, changes to the alignment can be automatically (and easily) animated too. Code: alignment-guides-animation.swift If you ever tried using alignment guides though, chances are, you … Read more

Inspecting the View Tree – Part 3: Nested Views

Inspecting the View Tree

Dealing with Preferences for Nested Views In the previous part of this series, we introduced SwiftUI anchor preferences. Now we are finally coming out of the forest. In this last part, we will put everything together. We will also learn how SwiftUI handles preferences of nested views, plus some other uses of Anchor<T>. As usual, … Read more

Inspecting the View Tree – Part 2: AnchorPreferences

Inspecting the View Tree

In the first part of this article, we introduced the use of preferences. These are very useful to communicate information upwards (from children to ancestors). By defining the associated type of our PreferenceKey, we now know that we can put anything we want in there. In this second part, the moment for Anchor Preferences to … Read more

Inspecting the View Tree – Part 1: PreferenceKey

Inspecting the View Tree

With SwiftUI, we normally don’t need to worry about what happens internally on our child views. Each happily does its own thing. However, life is not always normal. When we face these circumstances, SwiftUI provides us with some great tools. Unfortunately, its documentation is brief at best. This three part article tries to put a … Read more

GeometryReader to the Rescue


Most of the time, SwiftUI will do its Layout Magic and life will be wonderful. However, there are times (many times), when we require more control over the layout of our custom views. For these moments, we have several tools. The first one we are going to explore is GeometryReader. What the Parent Wants When … Read more

SwiftUI’s Layout Magic

SwiftUI Layout Magic

A New Way of Thinking As Apple put it during their 2019 WWDC, the new SwiftUI declarative views may be considered recipes. Each containing instructions on how to build themselves. Following on this food analogy, imagine you have the main recipe, which in turn is made of other preparations. A sauce, grilled fish, garnish, etc. … Read more

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.