Stage 2 · Lesson 3 of 10
Modifiers and their order
such as .padding(), .font(.headline), .foregroundStyle(.secondary) and .background() each return a new view that wraps the one before. So the order matters. Text("Hi").padding().background(.blue) colours the padded area.
.background(.blue).padding() colours only behind the text and leaves a clear gap around it. The same goes for .frame and .onTapGesture: a tap only registers on the area the modifier wraps, which may be smaller than it looks. Some modifiers, like .font, pass down to child views in a stack. To reuse a set of modifiers, write a custom ViewModifier or a view extension.
Common trapstacking modifiers until it looks right without understanding why.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CourseFreeSwiftUI Tutorials (Apple)
Apple · Beginner
Apple's own path from views and stacks to lists and navigation
- CourseFree100 Days of SwiftUI
Paul Hudson (Hacking with Swift) · Beginner
Days 16 to 35 build six small apps on views, modifiers, lists and animation