Exploring Rendering in SwiftUI

Learn when SwiftUI re-render subviews

Riccardo Cipolleschi
Better Programming

Photo by Viktor Forgacs on Unsplash

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

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (2)

What are your thoughts?

Just keep in mind that using _printChanges inside of a view body doesn't necessarily mean that view is being rendered. It's being evaluated to see if it or it's subviews should be rendered. A critical distinction.
Also it's not just properties. Using…...
I highly recommend Thinking In SwiftUI, where the authors take the reader through the rendering process, to anyone who's interested in a book that goes behind the scenes of SwiftUI rather than just showing what it does.