> For the complete documentation index, see [llms.txt](https://ios-course.cornellappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ios-course.cornellappdev.com/resources/archived-past-semesters/sp26/week-4-or-swiftui/monday-pre-lecture-skim.md).

# 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.&#x20;
* In SwiftUI (Declarative), you describe *what* the UI should look like and the framework handles the rest.&#x20;

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**:

```swift
Text("Hello")
    .padding(20)       // wraps Text in a padded view
    .background(.blue) // wraps THAT in a blue background
```

You'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:

```swift
var body: some View {
    Text("Hello, world!")
}
```

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?&#x20;

* Because after you chain a few modifiers, the actual type becomes something horrific like `ModifiedContent<ModifiedContent<Text, _PaddingLayout>, _BackgroundModifier<Color>>`. The `some` keyword lets Swift figure out the type for you while still guaranteeing it's a `View`. You don't need to fully understand opaque types right now — just know that `some View` is SwiftUI's way of saying "trust me, it's a view."

### Stacks = Layout

SwiftUI replaces Auto Layout constraints with three simple containers:

* &#x20;**HStack** — arranges views horizontally (left to right)
* &#x20;**VStack** — arranges views vertically (top to bottom)
* &#x20;**ZStack** — layers views on top of each other (back to front)

**HStack (horizontal)**, **VStack (vertical)**, **ZStack (layered).** Nest them to build any layout.&#x20;

**Spacer** is a flexible empty view that pushes other views apart. It expands to fill available space:

```swift
HStack {
    Text("Left")
    Spacer()
    Text("Right")
}
```

This pushes "Left" and "Right" to opposite edges — no constraints needed.
