🔖Monday Pre-lecture Skim
SP 2026 | Jay Zheng
Welcome to SwiftUI! This reading covers a few concepts that can feel unfamiliar the first time you see them. Skim through before lecture so the demos and examples click faster.
Declarative vs. Imperative
In UIKit (Imperative), you write step-by-step instructions for how to build UI.
In SwiftUI (Declarative), you describe what the UI should look like and the framework handles the rest.
If you catch yourself asking "when does this code run?" — that's the imperative mindset. In SwiftUI, you just keep your description up to date.
Structs! Not Classes
SwiftUI views are structs — lightweight value types with no inheritance baggage. Think of them as disposable blueprints, not long-lived objects you mutate over time.
If you're used to thinking of views as long-lived objects that get mutated over time, this is a mental shift!
Modifiers Create New Views
This is the big one. Each modifier wraps the previous view in a new view:
Text("Hello")
.padding(20) // wraps Text in a padded view
.background(.blue) // wraps THAT in a blue backgroundYou're not setting properties like for UILabel — you're nesting wrappers. That's why order matters: swapping .padding and .background changes the result (you will see during demo).
some View
You'll see this in every SwiftUI file:
You'll see var body: some View everywhere. It just means "this returns something that conforms to View" without you needing to spell out the gnarly concrete type. Don't overthink it.
Why not just write the type?
Because after you chain a few modifiers, the actual type becomes something horrific like
ModifiedContent<ModifiedContent<Text, _PaddingLayout>, _BackgroundModifier<Color>>. Thesomekeyword lets Swift figure out the type for you while still guaranteeing it's aView. You don't need to fully understand opaque types right now — just know thatsome Viewis SwiftUI's way of saying "trust me, it's a view."
Stacks = Layout
SwiftUI replaces Auto Layout constraints with three simple containers:
HStack — arranges views horizontally (left to right)
VStack — arranges views vertically (top to bottom)
ZStack — layers views on top of each other (back to front)
HStack (horizontal), VStack (vertical), ZStack (layered). Nest them to build any layout.
Spacer is a flexible empty view that pushes other views apart. It expands to fill available space:
This pushes "Left" and "Right" to opposite edges — no constraints needed.
Last updated
Was this helpful?