Dynamic Equality Checking and Equatable
Note that the arguments for
==
are defined asSelf
rather thanEquatable
. This has some implications and benefits[…][…]
The use of
Self
as inEquatable
’s definition restricts howEquatable
can be used. You cannot declare collections or variables as a protocol type, like you can in Objective-C.[…]
Many APIs vend
Any
, such asJSONSerialization
’s.jsonObject(_:_:)
methods. For testing purposes, you may want to compare the output of these methods to one another. You’ll quickly find you can’t[…]
See also: Adding a polymorphic Equatable?, Protocol-Oriented Programming in Swift.
Previously: