Difference between value type and reference type in Swift

value type in Swift

In Swift, A value type instance is an independent instance and holds its data in its own memory allocation.

reference type in Swift

In Swift, reference type instances share a single copy of their data, so that every new instance will point to the same address in memory.

value type vs reference type in Swift

Parametersvalue typereference type
Typestruct, enum, and tupleclass, functions, and closures
Assignment/PassingCopies data, creates a new instanceShares the same instance
ComparisonUse == for value equalityUse === for identity equality
MutationChanges don't affect originals Changes affect all references
Use CasesSimple, independent dataShared, mutable state, instance identity