Structs vs Classes
Value types vs reference types — and why SwiftUI and Swift concurrency favor structs.
Structs are value types: assigning or passing one creates an independent copy. Classes are reference types: every variable points to the same shared instance.
Default to structs. They are simpler to reason about, thread-safe when immutable, and are what SwiftUI views and most models should be.
Reach for a class when you need shared mutable identity, inheritance, deinit, or when a framework requires it — for example @Observable models and SwiftData @Model types.
1struct PointValue { var x = 0 }
2final class PointRef { var x = 0 }
3
4var a = PointValue()
5var b = a // copy
6b.x = 10
7print(a.x) // 0
8
9let c = PointRef()
10let d = c // same instance
11d.x = 10
12print(c.x) // 10Common pitfalls
- Mark classes final unless you design for inheritance — it is clearer and enables optimizations.
- Mutating a struct stored in a let constant is a compile error; use var.
Still unclear? Ask BeeAI about Structs vs Classes.
Get a tailored explanation, or paste your own code for a Swift 6 review. Free members get daily questions — Pro is unlimited.
Related topics
The modern replacement for ObservableObject/@Published — fine-grained updates with less boilerplate.
Understand the Sendable checks behind most Swift 6 errors — and how to fix them properly.
Turn a Swift class into a persistent model and wire the storage into your app with one modifier.
Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.
See Pro Plans