Thinking in SwiftUI

The one mental-model shift

You know Swift. Now you'll put pixels on an iPhone screen β€” and there's exactly one big idea to absorb first.

The old way to build UI is imperative: you give the screen orders, step by step. Find the booking-status label. Set its text to "confirmed". Set its color to green. And every place in your code where a booking can change, you must remember to go poke that label again β€” forget one spot and the screen shows stale, wrong data.

SwiftUI is declarative: you never poke the screen. Instead you write a description of what the screen looks like for a given state. "If the booking is confirmed, there's a green label saying confirmed." When the state changes, SwiftUI re-runs your description and updates the screen to match β€” automatically, everywhere, at once.

The slogan worth memorizing: UI is a function of state. Same state in, same pixels out. You manage the state; SwiftUI manages the pixels.