how come ~= and == means the same thing
They are not the same, but are similar in many cases.
In particular, ==
is an equality operator, used mainly by Equatable
protocol. While ~=
is a pattern matching operator, and is picked up by just about any pattern matching control flow, switch
, if case
, etc.
Now, since Equatable
implements ~=
by default, most ==
imply ~=
of the same meaning, but there are cases where only ~=
is appropriate, such as Range.~=
.
3 Likes