SwiftUI basics
Build a screen with views, state and modifiers.
What you will be able to do
- Compose views with stacks.
- Use @State for local state.
- Pass @Binding to child views.
- Use modifiers for layout and style.
In plain English
SwiftUI is declarative: views describe the UI for a state. @State owns local state, @Binding shares it and @StateObject owns a reference model. Views are structs and cheap to recreate.
struct CounterView: View {
@State private var count = 0
var body: some View {
VStack(spacing: 12) {
Text("Clicked \(count) times")
Button("Increment") { count += 1 }
}
.padding()
}
}Your turn
EasyAdd padding
Add 16 points of padding to a VStack.
SWIFT · starter
VStack { }Check your understanding before moving on.
Knowledge checkQuestion 1
Which property wrapper owns local value state?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.