Back to feed
Dev.to
Dev.to
7/23/2026
Swift classes vs structs: how let and var interact with reference and value types

Swift classes vs structs: how let and var interact with reference and value types

Original: Swift Classes — The Four Ways Variables and Constants Can Combine 🎭

Short summary

A clear explanation of why constant class instances allow property mutations while constant structs do not in Swift. Classes use reference semantics — a let locks the signpost but not the data it points to — while structs use value semantics where let freezes the entire value. The post walks through four combinations of constant/variable classes and properties with code examples.

  • Classes use reference semantics: let locks the signpost, not the data
  • Structs use value semantics: let freezes the entire value including properties
  • Four combinations of constant/variable classes and properties are explained with examples

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more