Back to Basics: Advanced Hashable

Video #300 • Oct 28, 2024 • Members Only

We zoom out a bit to get a greater appreciation for how Equatable and Hashable are used throughout the greater language and ecosystem, including actors, standard library types, SwiftUI, and more.

Collection
Equatable and Hashable
Back to Basics: Advanced Hashable
Locked

Unlock This Video

Our Free plan includes 1 members only video of your choice, plus weekly updates from our newsletter.

Sign in with GitHub

Introduction

So this proves that Swift Data has chosen to use referential identity for the Equatable and Hashable conformance of models, and we think this is the clearest sign that referential equality is typically the correct choice for classes. Even Swift Data models do not use structural equality, and they are classes that primarily represent simple data values held in some external store. So, if they can’t use structural equality, what hope do we have for other classes?

Brandon

There’s another situation where referential equality is the only way to make a reference Equatable, but it has to do with actors instead of classes. If you didn’t know, actors are reference types, but its stored properties are all protected by an isolation domain that requires you to await to access and mutate the properties if you are in a different isolation domain.

Let’s take a look.

Actors


References

Downloads

Get started with our free plan

Our free plan includes 1 members only episode of your choice, access to 75 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing