Reputation: 393
I encountered something similar to this in a codebase.
if varA !== varB {
// some code here...
}
Is that the same as
if varA! == varB {
// some code here...
}
which means that varA is force unwrapped?
Upvotes: 12
Views: 5996
Reputation: 77631
In swift ==
means "Are these objects equal?". While ===
means "Are these objects the same object?".
The first is a value equality check. The second is a pointer equality check.
The negation of these are !=
and !==
respectively.
Upvotes: 43
Reputation: 218818
In Swift, ===
and !==
are identity operators. They are used to determine if two objects refer to the same object instance.
So in that sample code, the condition is checking if varA
and varB
refer (or, rather, don't refer) to the same object instance even though they're different variables.
Upvotes: 6