Let's think about this for a moment
iOS UI used to be written with UIKit (imperative — 'update this view like this') or with Storyboard (visual drag-and-drop). SwiftUI, on the other hand, is a declarative UI framework — you write Swift code directly inside a struct conforming to the `View` protocol to describe 'what the UI should look like,' and whenever the data changes, SwiftUI automatically re-renders the UI — this maps closely to Android's Jetpack Compose concept (if you've read this site's Android tutorial, it'll feel immediately familiar).
Let's connect this to a real-world scenario
If you write `struct Greeting: View { let name: String; var body: some View { Text("Hello, \(name)!") } }`, calling `Greeting(name: "Aye Aye")` displays the text 'Hello, Aye Aye!' on screen. Add Xcode's `#Preview` macro and you can view the UI instantly without needing to run the Simulator.
Let's look at it together
import SwiftUI
struct Greeting: View {
let name: String
var body: some View {
Text("Hello, \(name)!")
}
}
#Preview {
Greeting(name: "Aye Aye")
}You should immediately see the text 'Hello, Aye Aye!' in the Xcode Preview panel, without needing to run the Simulator.Try it in 5 minutes
Write your own `Greeting` View and check it in the `#Preview` panel — try changing the name parameter and confirm that the preview auto-updates.
A quick word of caution
`#Preview` is meant for a quick look at your UI layout — interactive behavior like button taps and navigation can only really be tested on the Simulator (or a physical device).