Now that you understand the difference between value and reference types, you are ready to learn about equality and identity. Equality refers to two instances having the same values for their observable characteristics, such as two instances of the String type that have the same text. Identity, on the other hand, refers to whether two variables or constants point to the same instance in memory. Take a look at this sample code.
let x = 1 let y = 1 x == y // True
Two constants, x and y, are created.
They are both of type Int and hold on to the same value,
Not surprisingly, the equality check, done via
==, evaluates to
This makes sense because x and y hold on to exactly the same value.
This is exactly ...