Swift: Identity Operators

Comparing a pointer / instance in Objective C is easy:

object == anotherObject

But the == comparison in Swift checks the value and not the pointer, because there is no isEqual in Swift.
But how can we compare an instance in Swift when we don’t have the pointer?
Swift provides us identity operators to compare instances:
=== Identical to
!== Not Identiacal to

if tenEighty === alsoTenEighty {
    println("tenEighty and alsoTenEighty refer to the same Resolution instance.")

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/de/jEUH0.l

You can also use the Identity Operator to check if two arrays contain the same elements.

Leave a Reply

Your email address will not be published. Required fields are marked *