Swift Structs and Value Semantics
The confusion
Structs are often introduced as “just data.” That phrasing is too small for Swift, especially in app code where structs shape state flow, ownership, and copying behavior.
The important idea is that structs give you value semantics. That makes them easier to reason about than many mutable reference types.
What Swift is actually doing
A struct is copied when it is passed around, assigned, or stored in new places. That does not mean it is always expensive. It means the behavior is predictable.
That predictability is one reason SwiftUI leans so heavily on value types. The framework can rebuild views without making the objects themselves part of the UI identity story.
The mental model
Structs are a way to keep behavior and ownership easier to predict.
When you mutate a struct, you are changing the current value, not a shared object hidden somewhere else. That makes a feature easier to explain because the path of the data stays visible.
A small proof
struct Draft {
var name: String
}
var first = Draft(name: "Ana")
var second = first
second.name = "Ben"
first and second now diverge as separate values.
That is a tiny example, but it shows why value semantics are so useful in SwiftUI screens and feature models.
Why this matters in real apps
Value semantics make refactors safer. You can pass a struct through a stack of views or helper functions without worrying that some hidden alias changed the same object behind your back.
That is one reason SwiftUI code often becomes simpler when you move state to a clear owner and keep the rest as values.
Where this model breaks down
Large value graphs can still be expensive if you copy them carelessly. And not every model should be a struct; shared lifetime or identity can still call for a reference type.
So the lesson is not “always use structs.” The lesson is “understand the trade-off you get when you choose them.”
One sentence to remember
Structs make state easier to reason about because the value you see is the value you own.