junioriOS

Class vs Struct in Swift

Updated May 6, 2026

Short answer

Classes are reference types; structs are value types.

Deep explanation

Structs are copied when passed; classes share reference. Structs are safer and preferred unless inheritance is needed.

Real-world example

Use structs for models like API responses.

Common mistakes

  • Using classes unnecessarily causing shared mutable state.

Follow-up questions

  • What is value semantics?
  • Can structs conform to protocols?

More iOS interview questions

View all →