← Home

Swift's default hash changes every run

If you use a type’s default hash function in Swift, you get different results on every app run.

The reason is that Swift adds a random seed to hashes at runtime — a defense against hash-flooding attacks. The practical takeaway: don’t persist hash values to disk and expect them to stay the same on the next run.

Swift’s default hash producing different results each run