Bebekucing
Bebekucing

Reputation: 393

What does !== mean in Swift?

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

Answers (2)

Fogmeister
Fogmeister

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

David
David

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

Related Questions