Home

Introduction

Views are values, not objects

A SwiftUI view is a struct describing what should be on screen for the current state. It is not a thing you hold and mutate — it is created, read and thrown away, many times a second.

struct Counter: View {
    @State private var count = 0

    var body: some View {
        Button("Tapped \(count) times") { count += 1 }
    }
}

Counter is recreated on every state change. That sounds expensive and is not: the struct is a few bytes, and SwiftUI compares the new description with the old one to decide what actually needs redrawing.

Tip

The mental shift that makes everything else click: you never tell SwiftUI to update. You change state, and the view is a function of that state. Any time you find yourself wanting to “refresh the view”, the state model is wrong.

What this book covers

This is a template chapter. The full text is still being written.