Exploring Rendering in SwiftUI
Learn when SwiftUI re-render subviews
One of the amazing aspects of the Software engineering profession is that you never stop learning. You are exposed every day to different technologies: learning their basic concepts is one of the things that I personally like the most.
One of the most important skills to learn new technologies is the ability to recognize patterns and similarities. This allows you to reason about a new technology even if you don’t use it every day.
A week ago, a colleague of mine sent me this article on React rendering. I don’t use React every day, but I am familiar with its basic concepts and I couldn’t notice how similar SwiftUI it is. While reading the article, I was surprised to see that React re-renders when the state of a Component changes and not when its props do.
So, my curiosity tingled: what does SwiftUI do? When does it re-render its components? I created a small project to try and understand that and today I want to share my process and my findings.
Recreating the App
The first step I took was to reproduce the same situation of the one presented in the article. I created a new SwiftUI project with the same initial components:
- The
BigCountNumber