Swift Language Structs Structs are value types


Example

Unlike classes, which are passed by reference, structures are passed through copying:

first = "Hello"
second = first
first += " World!"
// first == "Hello World!"
// second == "Hello"

String is a structure, therefore it's copied on assignment.

Structures also cannot be compared using identity operator:

window0 === window1 // works because a window is a class instance
"hello" === "hello" // error: binary operator '===' cannot be applied to two 'String' operands

Every two structure instances are deemed identical if they compare equal.

Collectively, these traits that differentiate structures from classes are what makes structures value types.