Member-only story
The Inner Workings of State Properties in SwiftUI
It’s not magic — even though it seems to be

Hey! Just to clarify, this article is about the @State
property (unique to SwiftUI) and not the general concept of state. They’re related, but state itself is just an idea while the @State
property is an actual, visible, and tangible object. It’s also very versatile, almost like magic …
Background
If you’ve been working with SwiftUI, chances are that you once made a property and tried to change its value, only to get this weird error: “Cannot assign to property: ‘self’ is immutable.”

Above, pressedButton
is a var
, so its value is mutable (changeable) — but the error message says that “self” is immutable!

So pressedButton
is mutable, but self
isn’t? Let’s search up the error message.