image.png

image.png

1. Core Idea

SwiftUI builds a View Tree from your code.

Each view (ZStack, VStack, Text, etc.) is a struct that describes UI.

View ≠ actual UI
View = lightweight description of UI

2. View Tree Structure

Your UI is represented as a hierarchy:

ZStack
 ├── BackgroundView
 └── VStack
      ├── CityTextView
      ├── MainWeatherView
      ├── HStack (forecast)
      └── Button

Each node in this tree is a struct.


3. What Happens on State Change

When state changes:

SwiftUI does NOT mutate existing views

Instead:

1. Recreate entire view tree (structs)
2. Compare with previous tree (diffing)
3. Update only what changed