[Draft] Hasher & HashVisitable

You could make your type Codable and write an Encoder that builds a stable hash from codable types.

1 Like

Could you please move this to a new thread?

My API is forced to receive Hashable which I then need to convert into a stable value.

Your API is misusing Hashable, which is explicitly documented to not be stable across Swift versions (the hashing algorithm can be changed at any time) and app restarts (the random seed will change on every launch).

I do also wish that hash(into:) was generic over its Hasher (especially now that the new syntax would allow it to be a nice and succinct some Hasher), but that alternative was explicitly rejected.

You need to make a new Hashable-esque protocol for your app, which meets the needs of your specific business domain. Hashable is not "anything that can be hashed for any intent or purpose". It's very specific.

4 Likes