Home / Swift value vs reference types interview question

Swift language

Swift value vs reference types interview question

Struct versus class is one of the most common Swift interview questions because the answer reveals whether you understand semantics, not just syntax.

The core distinction

Structs are value types copied on assignment, so each variable owns its own data; classes are reference types shared by reference, so copies point at the same instance. Value semantics eliminate a whole category of shared mutable state and threading bugs, while classes give you identity, inheritance, and shared lifetime when you genuinely need them.

Design consequences and copy-on-write

Prefer structs by default for models and small data, and reach for a class when you need reference identity, inheritance, or a shared single source of truth. Copy-on-write, used by Array and Dictionary, keeps large value types cheap by deferring the copy until mutation, so value semantics rarely cost real performance.

Go deeper than a summary

Share Your Screen works topics like this through in full: 75 solved Swift problems with tests, 9 real case studies, and 7 annotated mock interviews, so you rehearse the live round instead of just reading about it.

Get the book

Frequently asked

When should you use a class over a struct?

When you need reference identity, inheritance, shared mutable state with a single owner, or Objective-C interop. Otherwise prefer a struct.

Does copying a large struct hurt performance?

Rarely, because standard collections use copy-on-write and only copy on mutation. For custom types you can adopt the same pattern if profiling shows a need.