SwiftUI is Apple's modern way to build UI for iPhone, iPad, Mac and Watch. Instead of manually updating views, you describe what the UI should look like for a given state, and SwiftUI keeps the screen in sync automatically.
Declarative vs imperative
In UIKit you say "create a label, then later set its text". In SwiftUI you say "there is a Text showing this value" — when the value changes, the Text updates itself.
Your first view
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, SwiftUI")
.font(.title)
.padding()
}
}
Use the Xcode live preview (the canvas on the right) to see changes instantly without running the app.
Tip: Every SwiftUI screen is a
struct conforming to View with a body property.Summary
SwiftUI is declarative: describe the UI for your data and it stays in sync. You built your first View and saw the live preview.