SwiftMidMCQ

What is the difference between `struct` and `class` in Swift?

Test your knowledge:

Explanation & Code

Answer: The core difference is value type vs reference type.

structclass
TypeValue typeReference type
MemoryStack (usually)Heap
InheritanceNoYes
MutabilityExplicit (mutating)Implicit
ARCNoYes
deinitNoYes

Rule of thumb:

  • Use struct by default — safer, faster, no retain cycles
  • Use class when you need identity, inheritance, or Objective-C interop

Rate your understanding:

Ready to practice more Swift?

Test yourself with our interactive quiz mode or browse all curated questions for this topic.