[swift-evolution] [Draft] Automatically deriving Equatable and Hashable for certain value types

Brent Royal-Gordon brent at architechies.com
Wed May 25 20:08:07 CDT 2016

> Omission of fields from generated computations
> Should it be possible to easily omit certain properties from automatically generated equality tests or hash value computation? This could be valuable, for example, if a property is merely used as an internal cache and does not actually contribute to the "value" of the instance. Under the rules above, if this cached value was equatable, a user would have to override == and hashValue and provide their own implementations to ignore it. If there is significant evidence that this pattern is common and useful, we could consider adding a custom attribute, such as @transient, that would omit the property from the generated computations.

A word of warning: an earlier proposal on memberwise initializers ran aground because it tried to annotate properties to tell the compiler which ones should be included in the generated initializer. It was ultimately judged too complex a solution for the specialized problem space it was trying to tackle.

In other words, Keep It Simple, Stupid. <https://en.wikipedia.org/wiki/KISS_principle>

Brent Royal-Gordon

More information about the swift-evolution mailing list