You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
SwiftUI is Apple's declarative framework for building user interfaces across all Apple platforms. This lesson covers the fundamentals of SwiftUI: views, modifiers, state management, layout, lists, and navigation.
SwiftUI is a declarative UI framework introduced at WWDC 2019. Instead of describing step-by-step how to build a UI (imperative), you declare what the UI should look like for a given state:
| Aspect | UIKit (Imperative) | SwiftUI (Declarative) |
|---|---|---|
| Approach | Describe steps to build UI | Describe what UI should look like |
| State changes | Manually update views | Automatic re-rendering |
| Layout | Auto Layout constraints | Declarative stacks and modifiers |
| Platforms | iOS/macOS specific | All Apple platforms |
| Preview | Run on simulator | Live preview in Xcode |
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, SwiftUI!")
.font(.title)
.foregroundStyle(.blue)
.padding()
}
}
Every SwiftUI view conforms to the View protocol and has a body property that returns some View.
Modifiers transform views and return new views:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.