Friday, May 17, 2019 [Tweets] [Favorites]

Dynamic Equality Checking and Equatable

Tanner Bennett (tweet):

Note that the arguments for == are defined as Self rather than Equatable. This has some implications and benefits[…]

[…]

The use of Self as in Equatable’s definition restricts how Equatable can be used. You cannot declare collections or variables as a protocol type, like you can in Objective-C.

[…]

Many APIs vend Any, such as JSONSerialization’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:

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment