Returns a Boolean value indicating whether two references point to the same
object instance.
This operator tests whether two instances have the same identity, not the
same value. For value equality, see the equal-to operator (==) and the
Equatable protocol.
The following example defines an IntegerRef type, an integer type with
reference semantics.
Because IntegerRef is a class, its instances can be compared using the
identical-to operator (===). In addition, because IntegerRef conforms
to the Equatable protocol, instances can also be compared using the
equal-to operator (==).
leta= IntegerRef(10)
letb= a
print(a== b)
// Prints "true"
print(a=== b)
// Prints "true"
The identical-to operator (===) returns false when comparing two
references to different object instances, even if the two instances have
the same value.
letc= IntegerRef(10)
print(a== c)
// Prints "true"
print(a=== c)
// Prints "false"
Parameters:lhs: A reference to compare.
rhs: Another reference to compare.
Returns a Boolean value indicating whether two references point to the same object instance.
This operator tests whether two instances have the same identity, not the same value. For value equality, see the equal-to operator (
==
) and theEquatable
protocol.The following example defines an
IntegerRef
type, an integer type with reference semantics.Because
IntegerRef
is a class, its instances can be compared using the identical-to operator (===
). In addition, becauseIntegerRef
conforms to theEquatable
protocol, instances can also be compared using the equal-to operator (==
).The identical-to operator (
===
) returnsfalse
when comparing two references to different object instances, even if the two instances have the same value.Parameters: lhs: A reference to compare. rhs: Another reference to compare.
See Also:
Equatable
,==
,!==
Declaration
func
===(
lhs
:
AnyObject
?,
rhs
:
AnyObject
?) -
>
Bool