Dynamic Equality Checking and Equatable
Note that the arguments for
==are defined asSelfrather thanEquatable. This has some implications and benefits[…][…]
The use of
Selfas inEquatable’s definition restricts howEquatablecan 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: