O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Equality versus identity

Two instances are equal if they have the same value. Equality is used to determine the equality of two value types. For instance, two strings are equal if they have the same text value. The == operator is used to check for equality. The following example presents equality checking for two Int numbers (Int is a value type):

let firstNumber = 1 let secondNumber = 1 if firstNumber == secondNumber {     print("Two numbers are equal") // prints "Two numbers are equal\n" }

On the other hand, two instances are identical if they refer to the same instance of memory. Identity is used to determine whether two reference types are identical. The === operator is used to check for identity. The following example presents identity ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required